Compressed texture API cleanup

Change-Id: I020bf6e79b5511adbd89931120feb76f359d83aa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/264056
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2020-01-13 13:02:26 -05:00 committed by Skia Commit-Bot
parent 3dbc701f6d
commit c558f72165
15 changed files with 48 additions and 35 deletions

View File

@ -67,9 +67,9 @@ protected:
}
void onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override {
sk_sp<SkImage> image = SkImage::MakeFromCompressed(context, fETC1Data,
kTexWidth, kTexHeight,
SkImage::CompressionType::kETC1);
auto image = SkImage::MakeFromCompressed(context, fETC1Data,
kTexWidth, kTexHeight,
SkImage::CompressionType::kETC2_RGB8_UNORM);
canvas->drawImage(image, 0, 0);
}

View File

@ -231,17 +231,25 @@ public:
return DecodeToTexture(ctx, data->data(), data->size(), subset);
}
// Experimental
/*
* Experimental:
* Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK
* -------------------------------------------------------------------------------------
* kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only)| ETC2_R8G8B8_UNORM
* | RGB8_ETC2 | |
* -------------------------------------------------------------------------------------
* kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM
*/
enum class CompressionType {
kNone,
kETC1,
kETC2_RGB8_UNORM, // the same as ETC1
kBC1_RGB8_UNORM,
kLast = kBC1_RGB8_UNORM,
};
static constexpr int kCompressionTypeCount = static_cast<int>(CompressionType::kLast) + 1;
static const CompressionType kETC1_CompressionType = CompressionType::kETC1;
static const CompressionType kETC1_CompressionType = CompressionType::kETC2_RGB8_UNORM;
/** Creates a GPU-backed SkImage from compressed data.

View File

@ -108,7 +108,7 @@ struct GrMockOptions {
fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888];
fCompressedOptions[(int)SkImage::CompressionType::kETC1].fTexturable = true;
fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true;
fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true;
}

View File

@ -1284,9 +1284,9 @@ static constexpr GrPixelConfig GrColorTypeToPixelConfig(GrColorType colorType) {
static constexpr GrPixelConfig GrCompressionTypeToPixelConfig(SkImage::CompressionType compression) {
switch (compression) {
case SkImage::CompressionType::kNone: return kUnknown_GrPixelConfig;
case SkImage::CompressionType::kETC1: return kRGB_ETC1_GrPixelConfig;
case SkImage::CompressionType::kBC1_RGB8_UNORM: return kRGB_BC1_GrPixelConfig;
case SkImage::CompressionType::kNone: return kUnknown_GrPixelConfig;
case SkImage::CompressionType::kETC2_RGB8_UNORM: return kRGB_ETC1_GrPixelConfig;
case SkImage::CompressionType::kBC1_RGB8_UNORM: return kRGB_BC1_GrPixelConfig;
}
SkUNREACHABLE;
@ -1359,9 +1359,9 @@ static constexpr const char* GrColorTypeToStr(GrColorType ct) {
static constexpr const char* GrCompressionTypeToStr(SkImage::CompressionType compression) {
switch (compression) {
case SkImage::CompressionType::kNone: return "kNone";
case SkImage::CompressionType::kETC1: return "kETC1";
case SkImage::CompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM";
case SkImage::CompressionType::kNone: return "kNone";
case SkImage::CompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM";
case SkImage::CompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM";
}
SkUNREACHABLE;
}

View File

@ -160,7 +160,7 @@ size_t GrCompressedDataSize(SkImage::CompressionType type, SkISize dimensions,
switch (type) {
case SkImage::CompressionType::kNone:
break;
case SkImage::CompressionType::kETC1:
case SkImage::CompressionType::kETC2_RGB8_UNORM:
case SkImage::CompressionType::kBC1_RGB8_UNORM: {
for (int i = 0; i < numMipLevels; ++i) {
int numBlocks = num_ETC1_blocks(dimensions.width(), dimensions.height());
@ -190,7 +190,7 @@ size_t GrCompressedRowBytes(SkImage::CompressionType type, int width) {
case SkImage::CompressionType::kNone:
return 0;
case SkImage::CompressionType::kBC1_RGB8_UNORM:
case SkImage::CompressionType::kETC1:
case SkImage::CompressionType::kETC2_RGB8_UNORM:
int numBlocksWidth = num_ETC1_blocks_w(width);
static_assert(sizeof(ETC1Block) == sizeof(BC1Block));
@ -204,7 +204,7 @@ SkISize GrCompressedDimensions(SkImage::CompressionType type, SkISize baseDimens
case SkImage::CompressionType::kNone:
return baseDimensions;
case SkImage::CompressionType::kBC1_RGB8_UNORM:
case SkImage::CompressionType::kETC1:
case SkImage::CompressionType::kETC2_RGB8_UNORM:
int numBlocksWidth = num_ETC1_blocks_w(baseDimensions.width());
int numBlocksHeight = num_ETC1_blocks_w(baseDimensions.height());
@ -294,7 +294,7 @@ void GrFillInCompressedData(SkImage::CompressionType type, SkISize dimensions,
for (int i = 0; i < numMipLevels; ++i) {
size_t levelSize = GrCompressedDataSize(type, dimensions, nullptr, GrMipMapped::kNo);
if (SkImage::CompressionType::kETC1 == type) {
if (SkImage::CompressionType::kETC2_RGB8_UNORM == type) {
fillin_ETC1_with_color(dimensions, colorf, &dstPixels[offset]);
} else {
SkASSERT(type == SkImage::CompressionType::kBC1_RGB8_UNORM);

View File

@ -3988,9 +3988,9 @@ SkImage::CompressionType GrGLCaps::compressionType(const GrBackendFormat& format
auto fmt = format.asGLFormat();
switch (fmt) {
case GrGLFormat::kCOMPRESSED_ETC1_RGB8: // same compression layout as RGB8_ETC2
case GrGLFormat::kCOMPRESSED_ETC1_RGB8: // same compression layout as ETC2_RGB8_UNORM
case GrGLFormat::kCOMPRESSED_RGB8_ETC2:
return SkImage::CompressionType::kETC1;
return SkImage::CompressionType::kETC2_RGB8_UNORM;
case GrGLFormat::kCOMPRESSED_RGB8_BC1:
return SkImage::CompressionType::kBC1_RGB8_UNORM;
default:
@ -4295,7 +4295,7 @@ GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType(
switch (compressionType) {
case SkImage::CompressionType::kNone:
return {};
case SkImage::CompressionType::kETC1:
case SkImage::CompressionType::kETC2_RGB8_UNORM:
// if ETC2 is available default to that format
if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_RGB8_ETC2)) {
return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_RGB8_ETC2, GR_GL_TEXTURE_2D);

View File

@ -258,6 +258,11 @@
#define GR_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
#define GR_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
#define GR_GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C
#define GR_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
#define GR_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
#define GR_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
#define GR_GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
#define GR_GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
#define GR_GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
@ -274,11 +279,11 @@
#define GR_GL_COMPRESSED_SIGNED_RG11_EAC 0x9273
#define GR_GL_COMPRESSED_RGB8_ETC2 0x9274
#define GR_GL_COMPRESSED_SRGB8 0x9275
#define GR_GL_COMPRESSED_SRGB8_ETC2 0x9275
#define GR_GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1 0x9276
#define GR_GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1 0x9277
#define GR_GL_COMPRESSED_RGBA8_ETC2 0x9278
#define GR_GL_COMPRESSED_SRGB8_ALPHA8_ETC2 0x9279
#define GR_GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
#define GR_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279
#define GR_GL_COMPRESSED_LUMINANCE_LATC1 0x8C70
#define GR_GL_COMPRESSED_SIGNED_LUMINANCE_LATC1 0x8C71

View File

@ -667,7 +667,7 @@ SkImage::CompressionType GrGLFormatToCompressionType(GrGLFormat format) {
switch (format) {
case GrGLFormat::kCOMPRESSED_RGB8_ETC2:
case GrGLFormat::kCOMPRESSED_ETC1_RGB8:
return SkImage::CompressionType::kETC1;
return SkImage::CompressionType::kETC2_RGB8_UNORM;
case GrGLFormat::kCOMPRESSED_RGB8_BC1:
return SkImage::CompressionType::kBC1_RGB8_UNORM;

View File

@ -57,9 +57,9 @@ std::vector<GrCaps::TestFormatColorTypeCombination> GrMockCaps::getTestingCombin
SkImage::CompressionType::kNone)},
// For these two compressed image formats the color type will effectively be RGB_888x
{ GrColorType::kRGB_888x, GrBackendFormat::MakeMock(GrColorType::kUnknown,
SkImage::CompressionType::kETC1)},
SkImage::CompressionType::kETC2_RGB8_UNORM)},
{ GrColorType::kRGB_888x, GrBackendFormat::MakeMock(GrColorType::kUnknown,
SkImage::CompressionType::kBC1_RGB8_UNORM)},
SkImage::CompressionType::kBC1_RGB8_UNORM)},
};

View File

@ -221,7 +221,7 @@ private:
}
SkImage::CompressionType compression = format.asMockCompressionType();
if (compression == SkImage::CompressionType::kETC1 ||
if (compression == SkImage::CompressionType::kETC2_RGB8_UNORM ||
compression == SkImage::CompressionType::kBC1_RGB8_UNORM) {
return ct == GrColorType::kRGB_888x; // TODO: this may be too restrictive
}

View File

@ -319,7 +319,7 @@ SkImage::CompressionType GrMtlCaps::compressionType(const GrBackendFormat& forma
switch (GrBackendFormatAsMTLPixelFormat(format)) {
case MTLPixelFormatETC2_RGB8:
// ETC2 uses the same compression layout as ETC1
return SkImage::CompressionType::kETC1;
return SkImage::CompressionType::kETC2_RGB8_UNORM;
default:
return SkImage::CompressionType::kNone;
}
@ -1040,7 +1040,7 @@ GrBackendFormat GrMtlCaps::getBackendFormatFromCompressionType(
switch (compressionType) {
case SkImage::CompressionType::kNone:
return {};
case SkImage::CompressionType::kETC1:
case SkImage::CompressionType::kETC2_RGB8_UNORM:
#ifdef SK_BUILD_FOR_MAC
return {};
#else

View File

@ -309,7 +309,7 @@ bool GrMtlFormatIsCompressed(MTLPixelFormat mtlFormat) {
SkImage::CompressionType GrMtlFormatToCompressionType(MTLPixelFormat mtlFormat) {
switch (mtlFormat) {
#ifdef SK_BUILD_FOR_IOS
case MTLPixelFormatETC2_RGB8: return SkImage::CompressionType::kETC1;
case MTLPixelFormatETC2_RGB8: return SkImage::CompressionType::kETC2_RGB8_UNORM;
#endif
default: return SkImage::CompressionType::kNone;
}

View File

@ -1281,7 +1281,7 @@ SkImage::CompressionType GrVkCaps::compressionType(const GrBackendFormat& format
}
switch (vkFormat) {
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: return SkImage::CompressionType::kETC1;
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: return SkImage::CompressionType::kETC2_RGB8_UNORM;
case VK_FORMAT_BC1_RGB_UNORM_BLOCK: return SkImage::CompressionType::kBC1_RGB8_UNORM;
default: return SkImage::CompressionType::kNone;
}
@ -1704,7 +1704,7 @@ GrBackendFormat GrVkCaps::getBackendFormatFromCompressionType(
switch (compressionType) {
case SkImage::CompressionType::kNone:
return {};
case SkImage::CompressionType::kETC1:
case SkImage::CompressionType::kETC2_RGB8_UNORM:
if (this->isVkFormatTexturable(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK)) {
return GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK);
}

View File

@ -185,7 +185,7 @@ bool GrVkFormatIsCompressed(VkFormat vkFormat) {
SkImage::CompressionType GrVkFormatToCompressionType(VkFormat vkFormat) {
switch (vkFormat) {
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: return SkImage::CompressionType::kETC1;
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: return SkImage::CompressionType::kETC2_RGB8_UNORM;
case VK_FORMAT_BC1_RGB_UNORM_BLOCK: return SkImage::CompressionType::kBC1_RGB8_UNORM;
default: return SkImage::CompressionType::kNone;
}

View File

@ -186,8 +186,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CompressedBackendAllocationTest, reporter, ct
SkImage::CompressionType fCompression;
SkColor4f fColor;
} combinations[] = {
{ SkImage::CompressionType::kETC1, SkColors::kRed },
{ SkImage::CompressionType::kBC1_RGB8_UNORM, SkColors::kBlue },
{ SkImage::CompressionType::kETC2_RGB8_UNORM, SkColors::kRed },
{ SkImage::CompressionType::kBC1_RGB8_UNORM, SkColors::kBlue },
};
for (auto combo : combinations) {