Remove GrCaps::isFormatTexturableAndUploadable

Instead separately check texturability and uploadability using existing
queries.

Also remove unused renderable param from onGetDefaultBackendFormat()

Change-Id: I8751e6d62263ddabd713c850beb788620a78bf10
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/279996
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-03-28 08:44:38 -04:00 committed by Skia Commit-Bot
parent d0b568b529
commit c18dad25e4
18 changed files with 41 additions and 129 deletions

View File

@ -352,19 +352,25 @@ GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrColorType srcColorT
return read;
}
GrBackendFormat GrCaps::getDefaultBackendFormat(GrColorType grColorType,
GrBackendFormat GrCaps::getDefaultBackendFormat(GrColorType colorType,
GrRenderable renderable) const {
GrBackendFormat format = this->onGetDefaultBackendFormat(grColorType, renderable);
if (!this->isFormatTexturableAndUploadable(grColorType, format)) {
auto format = this->onGetDefaultBackendFormat(colorType);
if (!this->isFormatTexturable(format)) {
return {};
}
if (renderable == GrRenderable::kYes) {
if (!this->isFormatAsColorTypeRenderable(grColorType, format)) {
return {};
}
if (!this->areColorTypeAndFormatCompatible(colorType, format)) {
return {};
}
// Currently we require that it be possible to write pixels into the "default" format. Perhaps,
// that could be a separate requirement from the caller. It seems less necessary if
// renderability was requested.
if (this->supportedReadPixelsColorType(colorType, format, colorType).fColorType ==
GrColorType::kUnknown) {
return {};
}
if (renderable == GrRenderable::kYes &&
!this->isFormatAsColorTypeRenderable(colorType, format)) {
return {};
}
return format;
}

View File

@ -186,9 +186,6 @@ public:
return this->compressionType(format) != SkImage::CompressionType::kNone;
}
// TODO: Once we use the supportWritePixels call for uploads, we can remove this function and
// instead only have the version that takes a GrBackendFormat.
virtual bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const = 0;
// Can a texture be made with the GrBackendFormat, and then be bound and sampled in a shader.
virtual bool isFormatTexturable(const GrBackendFormat&) const = 0;
@ -196,9 +193,7 @@ public:
virtual bool isFormatCopyable(const GrBackendFormat&) const = 0;
// Returns the maximum supported sample count for a format. 0 means the format is not renderable
// 1 means the format is renderable but doesn't support MSAA. This call only refers to the
// format itself. A caller should also confirm if the format is renderable with a given
// GrColorType by calling isFormatRenderable.
// 1 means the format is renderable but doesn't support MSAA.
virtual int maxRenderTargetSampleCount(const GrBackendFormat&) const = 0;
// Returns the number of samples to use when performing internal draws to the given config with
@ -540,7 +535,7 @@ private:
virtual bool onSurfaceSupportsWritePixels(const GrSurface*) const = 0;
virtual bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
const SkIRect& srcRect, const SkIPoint& dstPoint) const = 0;
virtual GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const = 0;
virtual GrBackendFormat onGetDefaultBackendFormat(GrColorType) const = 0;
// Backends should implement this if they have any extra requirements for use of window
// rectangles for a specific GrBackendRenderTarget outside of basic support.

View File

@ -52,7 +52,6 @@ GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType,
return GrBackendFormat();
}
SkASSERT(caps->isFormatTexturableAndUploadable(grColorType, format));
SkASSERT(renderable == GrRenderable::kNo ||
caps->isFormatAsColorTypeRenderable(grColorType, format));

View File

@ -446,8 +446,6 @@ bool GrGpu::writePixels(GrSurface* surface, int left, int top, int width, int he
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
SkASSERT(surface);
SkASSERT(!surface->framebufferOnly());
SkASSERT(this->caps()->isFormatTexturableAndUploadable(surfaceColorType,
surface->backendFormat()));
if (surface->readOnly()) {
return false;
@ -489,8 +487,6 @@ bool GrGpu::transferPixelsTo(GrTexture* texture, int left, int top, int width, i
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
SkASSERT(texture);
SkASSERT(transferBuffer);
SkASSERT(this->caps()->isFormatTexturableAndUploadable(textureColorType,
texture->backendFormat()));
if (texture->readOnly()) {
return false;

View File

@ -719,18 +719,6 @@ SkImage::CompressionType GrD3DCaps::compressionType(const GrBackendFormat& forma
SkUNREACHABLE;
}
bool GrD3DCaps::isFormatTexturableAndUploadable(GrColorType ct,
const GrBackendFormat& format) const {
DXGI_FORMAT dxgiFormat;
if (!format.asDxgiFormat(&dxgiFormat)) {
return false;
}
uint32_t ctFlags = this->getFormatInfo(dxgiFormat).colorTypeFlags(ct);
return this->isFormatTexturable(dxgiFormat) &&
SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag);
}
bool GrD3DCaps::isFormatTexturable(const GrBackendFormat& format) const {
DXGI_FORMAT dxgiFormat;
if (!format.asDxgiFormat(&dxgiFormat)) {
@ -905,11 +893,10 @@ GrColorType GrD3DCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&
SkUNREACHABLE;
}
GrBackendFormat GrD3DCaps::onGetDefaultBackendFormat(GrColorType ct,
GrRenderable renderable) const {
GrBackendFormat GrD3DCaps::onGetDefaultBackendFormat(GrColorType ct) const {
DXGI_FORMAT format = this->getFormatFromColorType(ct);
if (format == DXGI_FORMAT_UNKNOWN) {
return GrBackendFormat();
return {};
}
return GrBackendFormat::MakeDxgi(format);
}

View File

@ -27,7 +27,6 @@ public:
bool isFormatSRGB(const GrBackendFormat&) const override;
SkImage::CompressionType compressionType(const GrBackendFormat&) const override;
bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override;
bool isFormatTexturable(const GrBackendFormat&) const override;
bool isFormatTexturable(DXGI_FORMAT) const;
@ -101,7 +100,7 @@ private:
bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override;
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;

View File

@ -73,25 +73,6 @@ static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorTyp
return GrSwizzle::RGBA();
}
bool GrDawnCaps::isFormatTexturableAndUploadable(GrColorType ct,
const GrBackendFormat& format) const {
wgpu::TextureFormat dawnFormat;
if (!format.asDawnFormat(&dawnFormat)) {
return false;
}
switch (ct) {
case GrColorType::kAlpha_8:
return wgpu::TextureFormat::R8Unorm == dawnFormat;
case GrColorType::kRGBA_8888:
case GrColorType::kRGB_888x:
case GrColorType::kBGRA_8888:
return wgpu::TextureFormat::RGBA8Unorm == dawnFormat ||
wgpu::TextureFormat::BGRA8Unorm == dawnFormat;
default:
return false;
}
}
bool GrDawnCaps::isFormatRenderable(const GrBackendFormat& format,
int sampleCount) const {
wgpu::TextureFormat dawnFormat;
@ -128,11 +109,10 @@ int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const
return format.isValid() ? 1 : 0;
}
GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct,
GrRenderable renderable) const {
GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct) const {
wgpu::TextureFormat format;
if (!GrColorTypeToDawnFormat(ct, &format)) {
return GrBackendFormat();
return {};
}
return GrBackendFormat::MakeDawn(format);
}

View File

@ -20,7 +20,6 @@ public:
bool isFormatSRGB(const GrBackendFormat&) const override;
SkImage::CompressionType compressionType(const GrBackendFormat&) const override;
bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat& format) const override;
bool isFormatRenderable(const GrBackendFormat& format,
int sampleCount = 1) const override;
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
@ -73,7 +72,7 @@ private:
const SkIRect& srcRect, const SkIPoint& dstPoint) const override {
return true;
}
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override;
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;

View File

@ -4111,15 +4111,6 @@ SkImage::CompressionType GrGLCaps::compressionType(const GrBackendFormat& format
SkUNREACHABLE;
}
bool GrGLCaps::isFormatTexturableAndUploadable(GrColorType ct,
const GrBackendFormat& format) const {
auto glFormat = format.asGLFormat();
const FormatInfo& info = this->getFormatInfo(glFormat);
return this->isFormatTexturable(glFormat) &&
SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kUploadData_Flag);
}
bool GrGLCaps::isFormatTexturable(const GrBackendFormat& format) const {
return this->isFormatTexturable(format.asGLFormat());
}
@ -4293,12 +4284,10 @@ GrColorType GrGLCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& f
SkUNREACHABLE;
}
GrBackendFormat GrGLCaps::onGetDefaultBackendFormat(GrColorType ct,
GrRenderable renderable) const {
// TODO: make use of renderable.
GrBackendFormat GrGLCaps::onGetDefaultBackendFormat(GrColorType ct) const {
auto format = this->getFormatFromColorType(ct);
if (format == GrGLFormat::kUnknown) {
return GrBackendFormat();
return {};
}
return GrBackendFormat::MakeGL(GrGLFormatToEnum(format), GR_GL_TEXTURE_2D);
}

View File

@ -116,7 +116,6 @@ public:
bool isFormatSRGB(const GrBackendFormat&) const override;
SkImage::CompressionType compressionType(const GrBackendFormat&) const override;
bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override;
bool isFormatTexturable(const GrBackendFormat&) const override;
bool isFormatTexturable(GrGLFormat) const;
@ -501,7 +500,7 @@ private:
bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override;
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&,

View File

@ -53,11 +53,6 @@ public:
return format.asMockCompressionType();
}
bool isFormatTexturableAndUploadable(GrColorType,
const GrBackendFormat& format) const override {
return this->isFormatTexturable(format);
}
bool isFormatTexturable(const GrBackendFormat& format) const override {
SkImage::CompressionType compression = format.asMockCompressionType();
if (compression != SkImage::CompressionType::kNone) {
@ -190,7 +185,7 @@ private:
const SkIRect& srcRect, const SkIPoint& dstPoint) const override {
return true;
}
GrBackendFormat onGetDefaultBackendFormat(GrColorType ct, GrRenderable) const override {
GrBackendFormat onGetDefaultBackendFormat(GrColorType ct) const override {
return GrBackendFormat::MakeMock(ct, SkImage::CompressionType::kNone);
}

View File

@ -29,7 +29,6 @@ public:
bool isFormatSRGB(const GrBackendFormat&) const override;
SkImage::CompressionType compressionType(const GrBackendFormat&) const override;
bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override;
bool isFormatTexturable(const GrBackendFormat&) const override;
bool isFormatTexturable(MTLPixelFormat) const;
@ -111,7 +110,7 @@ private:
bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override;
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&,

View File

@ -331,15 +331,6 @@ SkImage::CompressionType GrMtlCaps::compressionType(const GrBackendFormat& forma
SkUNREACHABLE;
}
bool GrMtlCaps::isFormatTexturableAndUploadable(GrColorType ct,
const GrBackendFormat& format) const {
MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
uint32_t ctFlags = this->getFormatInfo(mtlFormat).colorTypeFlags(ct);
return this->isFormatTexturable(mtlFormat) &&
SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag);
}
bool GrMtlCaps::isFormatTexturable(const GrBackendFormat& format) const {
MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
return this->isFormatTexturable(mtlFormat);
@ -909,11 +900,10 @@ GrColorType GrMtlCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&
}
}
GrBackendFormat GrMtlCaps::onGetDefaultBackendFormat(GrColorType ct,
GrRenderable renderable) const {
GrBackendFormat GrMtlCaps::onGetDefaultBackendFormat(GrColorType ct) const {
MTLPixelFormat format = this->getFormatFromColorType(ct);
if (!format) {
return GrBackendFormat();
return {};
}
return GrBackendFormat::MakeMtl(format);
}

View File

@ -262,9 +262,9 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, int left, int top, int width,
if (width == 0 || height == 0) {
return false;
}
if (!this->mtlCaps().isFormatTexturableAndUploadable(dataColorType, tex->backendFormat())) {
return false;
}
SkASSERT(this->mtlCaps().surfaceSupportsWritePixels(tex));
SkASSERT(this->mtlCaps().areColorTypeAndFormatCompatible(dataColorType, tex->backendFormat()));
id<MTLTexture> mtlTexture = tex->mtlTexture();
SkASSERT(mtlTexture);

View File

@ -1312,18 +1312,6 @@ SkImage::CompressionType GrVkCaps::compressionType(const GrBackendFormat& format
SkUNREACHABLE;
}
bool GrVkCaps::isFormatTexturableAndUploadable(GrColorType ct,
const GrBackendFormat& format) const {
VkFormat vkFormat;
if (!format.asVkFormat(&vkFormat)) {
return false;
}
uint32_t ctFlags = this->getFormatInfo(vkFormat).colorTypeFlags(ct);
return this->isVkFormatTexturable(vkFormat) &&
SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag);
}
bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format) const {
VkFormat vkFormat;
if (!format.asVkFormat(&vkFormat)) {
@ -1562,11 +1550,10 @@ GrColorType GrVkCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& f
SkUNREACHABLE;
}
GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct,
GrRenderable renderable) const {
GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct) const {
VkFormat format = this->getFormatFromColorType(ct);
if (format == VK_FORMAT_UNDEFINED) {
return GrBackendFormat();
return {};
}
return GrBackendFormat::MakeVk(format);
}

View File

@ -35,7 +35,6 @@ public:
bool isFormatSRGB(const GrBackendFormat&) const override;
SkImage::CompressionType compressionType(const GrBackendFormat&) const override;
bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override;
bool isFormatTexturable(const GrBackendFormat&) const override;
bool isVkFormatTexturable(VkFormat) const;
@ -224,7 +223,7 @@ private:
bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override;
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;

View File

@ -762,9 +762,8 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, int left, int top, int widt
return false;
}
if (!this->vkCaps().isFormatTexturableAndUploadable(dataColorType, tex->backendFormat())) {
return false;
}
SkASSERT(this->vkCaps().surfaceSupportsWritePixels(tex));
SkASSERT(this->vkCaps().areColorTypeAndFormatCompatible(dataColorType, tex->backendFormat()));
// For RGB_888x src data we are uploading it first to an RGBA texture and then copying it to the
// dst RGB texture. Thus we do not upload mip levels for that.

View File

@ -123,13 +123,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
// support check is working
{
bool isCompressed = caps->isFormatCompressed(combo.fFormat);
bool isTexturable;
if (isCompressed) {
isTexturable = caps->isFormatTexturable(combo.fFormat);
} else {
isTexturable =
caps->isFormatTexturableAndUploadable(combo.fColorType, combo.fFormat);
}
bool isTexturable = caps->isFormatTexturable(combo.fFormat);
sk_sp<GrSurface> tex = createTexture(kDims, combo.fColorType, combo.fFormat,
GrRenderable::kNo, resourceProvider);
@ -222,7 +216,7 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) {
SkASSERT(combo.fColorType != GrColorType::kUnknown);
SkASSERT(combo.fFormat.isValid());
if (!caps->isFormatTexturableAndUploadable(combo.fColorType, combo.fFormat)) {
if (!caps->isFormatTexturable(combo.fFormat)) {
continue;
}