Add GrCaps::getConfigFromCompressedBackendFormat
When wrapping a backend texture we currently need to derive a GrPixelConfig from the backend format. The normal caps method (i.e., getConfigFromBackendFormat) is inappropriate for the compressed backend texture use case. Bug: skia:9680 Change-Id: Ic4de7550c9a11f6e6207374c27d0ea23b8ab1575 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/260044 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
77912983a3
commit
df6c734253
@ -396,6 +396,9 @@ public:
|
||||
|
||||
return this->onGetConfigFromBackendFormat(format, grCT);
|
||||
}
|
||||
GrPixelConfig getConfigFromCompressedBackendFormat(const GrBackendFormat& format) const {
|
||||
return this->onGetConfigFromCompressedBackendFormat(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special method only for YUVA images. Returns a colortype that matches the backend format or
|
||||
@ -561,6 +564,7 @@ private:
|
||||
|
||||
virtual GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat& format,
|
||||
GrColorType ct) const = 0;
|
||||
virtual GrPixelConfig onGetConfigFromCompressedBackendFormat(const GrBackendFormat&) const = 0;
|
||||
|
||||
virtual bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const = 0;
|
||||
|
||||
|
@ -87,6 +87,10 @@ GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& fo
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
GrPixelConfig GrDawnCaps::onGetConfigFromCompressedBackendFormat(const GrBackendFormat&) const {
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType,
|
||||
bool forOutput) {
|
||||
switch (colorType) {
|
||||
|
@ -75,6 +75,7 @@ private:
|
||||
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
|
||||
|
||||
GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override;
|
||||
GrPixelConfig onGetConfigFromCompressedBackendFormat(const GrBackendFormat&) const override;
|
||||
|
||||
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
|
||||
|
||||
|
@ -4163,6 +4163,17 @@ GrPixelConfig GrGLCaps::onGetConfigFromBackendFormat(const GrBackendFormat& form
|
||||
return validate_sized_format(format.asGLFormat(), ct, fStandard);
|
||||
}
|
||||
|
||||
GrPixelConfig GrGLCaps::onGetConfigFromCompressedBackendFormat(const GrBackendFormat& f) const {
|
||||
GrGLFormat glFormat = f.asGLFormat();
|
||||
|
||||
if (glFormat == GrGLFormat::kCOMPRESSED_RGB8_ETC2 ||
|
||||
glFormat == GrGLFormat::kCOMPRESSED_ETC1_RGB8) {
|
||||
return kRGB_ETC1_GrPixelConfig;
|
||||
}
|
||||
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
GrColorType GrGLCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format,
|
||||
bool isAlphaChannel) const {
|
||||
switch (format.asGLFormat()) {
|
||||
@ -4208,7 +4219,10 @@ GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType(
|
||||
if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_RGB8_ETC2)) {
|
||||
return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_RGB8_ETC2, GR_GL_TEXTURE_2D);
|
||||
}
|
||||
return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D);
|
||||
if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_ETC1_RGB8)) {
|
||||
return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
SkUNREACHABLE;
|
||||
|
@ -474,6 +474,7 @@ private:
|
||||
const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
|
||||
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
|
||||
GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override;
|
||||
GrPixelConfig onGetConfigFromCompressedBackendFormat(const GrBackendFormat&) const override;
|
||||
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
|
||||
|
||||
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&,
|
||||
|
@ -645,35 +645,3 @@ bool GrGLFormatIsCompressed(GrGLFormat format) {
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
bool GrGLFormatToCompressionType(GrGLFormat format, SkImage::CompressionType* compressionType) {
|
||||
switch (format) {
|
||||
case GrGLFormat::kCOMPRESSED_RGB8_ETC2:
|
||||
case GrGLFormat::kCOMPRESSED_ETC1_RGB8:
|
||||
*compressionType = SkImage::CompressionType::kETC1;
|
||||
return true;
|
||||
|
||||
case GrGLFormat::kRGBA8:
|
||||
case GrGLFormat::kR8:
|
||||
case GrGLFormat::kALPHA8:
|
||||
case GrGLFormat::kLUMINANCE8:
|
||||
case GrGLFormat::kBGRA8:
|
||||
case GrGLFormat::kRGB565:
|
||||
case GrGLFormat::kRGBA16F:
|
||||
case GrGLFormat::kR16F:
|
||||
case GrGLFormat::kLUMINANCE16F:
|
||||
case GrGLFormat::kRGB8:
|
||||
case GrGLFormat::kRG8:
|
||||
case GrGLFormat::kRGB10_A2:
|
||||
case GrGLFormat::kRGBA4:
|
||||
case GrGLFormat::kSRGB8_ALPHA8:
|
||||
case GrGLFormat::kR16:
|
||||
case GrGLFormat::kRG16:
|
||||
case GrGLFormat::kRGBA16:
|
||||
case GrGLFormat::kRG16F:
|
||||
case GrGLFormat::kUnknown:
|
||||
return false;
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
|
@ -373,9 +373,4 @@ GrGLenum GrToGLStencilFunc(GrStencilTest test);
|
||||
*/
|
||||
bool GrGLFormatIsCompressed(GrGLFormat);
|
||||
|
||||
/**
|
||||
* Maps a GrGLFormat into the CompressionType enum if appropriate.
|
||||
*/
|
||||
bool GrGLFormatToCompressionType(GrGLFormat, SkImage::CompressionType*);
|
||||
|
||||
#endif
|
||||
|
@ -196,12 +196,24 @@ private:
|
||||
GrColorType) const override {
|
||||
SkImage::CompressionType compression = format.asMockCompressionType();
|
||||
if (compression != SkImage::CompressionType::kNone) {
|
||||
return GrCompressionTypeToPixelConfig(compression);
|
||||
// This emulates the behavior of the other backends which validate
|
||||
// the format w/ the colorType
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
return GrColorTypeToPixelConfig(format.asMockColorType());
|
||||
}
|
||||
|
||||
GrPixelConfig onGetConfigFromCompressedBackendFormat(const GrBackendFormat& f) const override {
|
||||
SkImage::CompressionType compression = f.asMockCompressionType();
|
||||
if (compression != SkImage::CompressionType::kNone) {
|
||||
return GrCompressionTypeToPixelConfig(compression);
|
||||
}
|
||||
|
||||
// This emulates the behavior of the other backends
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
bool onAreColorTypeAndFormatCompatible(GrColorType ct,
|
||||
const GrBackendFormat& format) const override {
|
||||
if (ct == GrColorType::kUnknown) {
|
||||
|
@ -110,6 +110,7 @@ private:
|
||||
const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
|
||||
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
|
||||
GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override;
|
||||
GrPixelConfig onGetConfigFromCompressedBackendFormat(const GrBackendFormat&) const override;
|
||||
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
|
||||
|
||||
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&,
|
||||
|
@ -994,6 +994,18 @@ GrPixelConfig GrMtlCaps::onGetConfigFromBackendFormat(const GrBackendFormat& for
|
||||
return validate_sized_format(GrBackendFormatAsMTLPixelFormat(format), ct);
|
||||
}
|
||||
|
||||
GrPixelConfig GrMtlCaps::onGetConfigFromCompressedBackendFormat(const GrBackendFormat& f) const {
|
||||
|
||||
switch (GrBackendFormatAsMTLPixelFormat(f)) {
|
||||
#ifdef SK_BUILD_FOR_IOS
|
||||
case MTLPixelFormatETC2_RGB8: return kRGB_ETC1_GrPixelConfig;
|
||||
#endif
|
||||
default: return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
GrColorType GrMtlCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format,
|
||||
bool isAlphaChannel) const {
|
||||
switch (GrBackendFormatAsMTLPixelFormat(format)) {
|
||||
|
@ -1627,6 +1627,18 @@ GrPixelConfig GrVkCaps::onGetConfigFromBackendFormat(const GrBackendFormat& form
|
||||
return validate_image_info(vkFormat, ct, ycbcrInfo->isValid());
|
||||
}
|
||||
|
||||
GrPixelConfig GrVkCaps::onGetConfigFromCompressedBackendFormat(const GrBackendFormat& f) const {
|
||||
VkFormat vkFormat;
|
||||
if (!f.asVkFormat(&vkFormat)) {
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
if (vkFormat == VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK) {
|
||||
return kRGB_ETC1_GrPixelConfig;
|
||||
}
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
GrColorType GrVkCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format,
|
||||
bool isAlphaChannel) const {
|
||||
VkFormat vkFormat;
|
||||
|
@ -225,6 +225,8 @@ private:
|
||||
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
|
||||
|
||||
GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override;
|
||||
GrPixelConfig onGetConfigFromCompressedBackendFormat(const GrBackendFormat&) const override;
|
||||
|
||||
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
|
||||
|
||||
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&,
|
||||
|
@ -131,7 +131,12 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fWidth = kW;
|
||||
desc.fHeight = kH;
|
||||
desc.fConfig = caps->getConfigFromBackendFormat(combo.fFormat, combo.fColorType);
|
||||
|
||||
if (caps->isFormatCompressed(combo.fFormat)) {
|
||||
desc.fConfig = caps->getConfigFromCompressedBackendFormat(combo.fFormat);
|
||||
} else {
|
||||
desc.fConfig = caps->getConfigFromBackendFormat(combo.fFormat, combo.fColorType);
|
||||
}
|
||||
SkASSERT(desc.fConfig != kUnknown_GrPixelConfig);
|
||||
|
||||
// Check if 'isFormatTexturable' agrees with 'createTexture' and that the mipmap
|
||||
|
Loading…
Reference in New Issue
Block a user