Switch SkImage::CompressionType to be an enum class

Following CLs use CompressionType much more widely so let's switch it first.

Bug: skia:9680
Change-Id: Ie8847f24936e90dd85e0ad79cbe5542d68c87b12
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/258882
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Robert Phillips 2019-12-10 10:05:06 -05:00 committed by Skia Commit-Bot
parent 7da1a13cee
commit ab2b722fdd
12 changed files with 45 additions and 26 deletions

View File

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

View File

@ -232,11 +232,16 @@ public:
}
// Experimental
enum CompressionType {
kETC1_CompressionType,
kLast_CompressionType = kETC1_CompressionType,
enum class CompressionType {
kNone,
kETC1,
kLast = kETC1,
};
static constexpr int kCompressionTypeCount = static_cast<int>(CompressionType::kLast) + 1;
static const CompressionType kETC1_CompressionType = CompressionType::kETC1;
/** Creates a GPU-backed SkImage from compressed data.
SkImage is returned if format of the compressed data is supported.

View File

@ -811,7 +811,8 @@ GR_MAKE_BITFIELD_CLASS_OPS(GpuPathRenderers)
static constexpr GrPixelConfig GrCompressionTypePixelConfig(SkImage::CompressionType compression) {
switch (compression) {
case SkImage::kETC1_CompressionType: return kRGB_ETC1_GrPixelConfig;
case SkImage::CompressionType::kNone: return kUnknown_GrPixelConfig;
case SkImage::CompressionType::kETC1: return kRGB_ETC1_GrPixelConfig;
}
SkUNREACHABLE;
}
@ -822,13 +823,14 @@ static constexpr GrPixelConfig GrCompressionTypePixelConfig(SkImage::Compression
static inline size_t GrCompressedFormatDataSize(SkImage::CompressionType compressionType,
SkISize dimensions) {
switch (compressionType) {
case SkImage::kETC1_CompressionType:
case SkImage::CompressionType::kNone:
return 0;
case SkImage::CompressionType::kETC1:
SkASSERT((dimensions.width() & 3) == 0);
SkASSERT((dimensions.height() & 3) == 0);
return (dimensions.width() >> 2) * (dimensions.height() >> 2) * 8;
}
SK_ABORT("Invalid pixel config");
SkUNREACHABLE;
}
/**

View File

@ -123,20 +123,24 @@ static int num_ETC1_blocks(int w, int h) {
size_t GrCompressedDataSize(SkImage::CompressionType type, int width, int height) {
switch (type) {
case SkImage::kETC1_CompressionType:
case SkImage::CompressionType::kNone:
return 0;
case SkImage::CompressionType::kETC1:
int numBlocks = num_ETC1_blocks(width, height);
return numBlocks * sizeof(ETC1Block);
}
SK_ABORT("Unexpected compression type");
SkUNREACHABLE;
}
size_t GrCompressedRowBytes(SkImage::CompressionType type, int width) {
switch (type) {
case SkImage::kETC1_CompressionType:
case SkImage::CompressionType::kNone:
return 0;
case SkImage::CompressionType::kETC1:
int numBlocksWidth = num_ETC1_blocks_w(width);
return numBlocksWidth * sizeof(ETC1Block);
}
SK_ABORT("Unexpected compression type");
SkUNREACHABLE;
}
// Fill in 'dest' with ETC1 blocks derived from 'colorf'
@ -193,7 +197,7 @@ void GrFillInCompressedData(SkImage::CompressionType type, int baseWidth, int ba
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
int currentWidth = baseWidth;
int currentHeight = baseHeight;
if (SkImage::kETC1_CompressionType == type) {
if (SkImage::CompressionType::kETC1 == type) {
fillin_ETC1_with_color(currentWidth, currentHeight, colorf, dstPixels);
}
}

View File

@ -276,7 +276,7 @@ sk_sp<GrTexture> GrGpu::createCompressedTexture(int width, int height,
size_t dataSize) {
// If we ever add a new CompressionType, we should add a check here to make sure the
// GrBackendFormat and CompressionType are compatible with eachother.
SkASSERT(compressionType == SkImage::kETC1_CompressionType);
SkASSERT(compressionType == SkImage::CompressionType::kETC1);
this->handleDirtyContext();
if (width < 1 || width > this->caps()->maxTextureSize() ||

View File

@ -34,7 +34,7 @@ size_t GrSurface::ComputeSize(const GrCaps& caps,
}
// Just setting a defualt value here to appease warnings on uninitialized object.
SkImage::CompressionType compressionType = SkImage::kETC1_CompressionType;
SkImage::CompressionType compressionType = SkImage::CompressionType::kNone;
if (caps.isFormatCompressed(format, &compressionType)) {
colorSize = GrCompressedFormatDataSize(compressionType, dimensions);
} else {

View File

@ -3917,7 +3917,7 @@ bool GrGLCaps::isFormatCompressed(const GrBackendFormat& format,
case GrGLFormat::kCOMPRESSED_RGB8_ETC2: // fall through
case GrGLFormat::kCOMPRESSED_ETC1_RGB8:
// ETC2 uses the same compression layout as ETC1
*compressionTypePtr = SkImage::kETC1_CompressionType;
*compressionTypePtr = SkImage::CompressionType::kETC1;
return true;
default:
return false;
@ -4201,14 +4201,17 @@ GrBackendFormat GrGLCaps::onGetDefaultBackendFormat(GrColorType ct,
GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType(
SkImage::CompressionType compressionType) const {
switch (compressionType) {
case SkImage::kETC1_CompressionType:
case SkImage::CompressionType::kNone:
return {};
case SkImage::CompressionType::kETC1:
// 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);
}
return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D);
}
SK_ABORT("Invalid compression type");
SkUNREACHABLE;
}
GrSwizzle GrGLCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const {

View File

@ -650,7 +650,7 @@ bool GrGLFormatToCompressionType(GrGLFormat format, SkImage::CompressionType* co
switch (format) {
case GrGLFormat::kCOMPRESSED_RGB8_ETC2:
case GrGLFormat::kCOMPRESSED_ETC1_RGB8:
*compressionType = SkImage::kETC1_CompressionType;
*compressionType = SkImage::CompressionType::kETC1;
return true;
case GrGLFormat::kRGBA8:

View File

@ -1028,7 +1028,9 @@ GrBackendFormat GrMtlCaps::onGetDefaultBackendFormat(GrColorType ct,
GrBackendFormat GrMtlCaps::getBackendFormatFromCompressionType(
SkImage::CompressionType compressionType) const {
switch (compressionType) {
case SkImage::kETC1_CompressionType:
case SkImage::CompressionType::kNone:
return {};
case SkImage::CompressionType::kETC1:
#ifdef SK_BUILD_FOR_MAC
return {};
#else

View File

@ -1261,7 +1261,7 @@ bool GrVkCaps::isFormatCompressed(const GrBackendFormat& format,
switch (vkFormat) {
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
// ETC2 uses the same compression layout as ETC1
*compressionTypePtr = SkImage::kETC1_CompressionType;
*compressionTypePtr = SkImage::CompressionType::kETC1;
return true;
default:
return false;
@ -1666,10 +1666,13 @@ GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct,
GrBackendFormat GrVkCaps::getBackendFormatFromCompressionType(
SkImage::CompressionType compressionType) const {
switch (compressionType) {
case SkImage::kETC1_CompressionType:
case SkImage::CompressionType::kNone:
return {};
case SkImage::CompressionType::kETC1:
return GrBackendFormat::MakeVk(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK);
}
SK_ABORT("Invalid compression type");
SkUNREACHABLE;
}
GrSwizzle GrVkCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const {

View File

@ -182,7 +182,7 @@ bool GrVkFormatIsCompressed(VkFormat vkFormat) {
bool GrVkFormatToCompressionType(VkFormat vkFormat, SkImage::CompressionType* compressionType) {
switch (vkFormat) {
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
*compressionType = SkImage::kETC1_CompressionType;
*compressionType = SkImage::CompressionType::kETC1;
return true;
default:
return false;

View File

@ -94,7 +94,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
SkImage::CompressionType type;
switch (config) {
case kRGB_ETC1_GrPixelConfig:
type = SkImage::kETC1_CompressionType;
type = SkImage::CompressionType::kETC1;
break;
default:
SK_ABORT("Unexpected config");
@ -106,7 +106,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
SkColor4f color = {0, 0, 0, 0};
GrFillInCompressedData(type, width, height, (char*)data->writable_data(), color);
return rp->createCompressedTexture(width, height, format,
SkImage::kETC1_CompressionType,
SkImage::CompressionType::kETC1,
SkBudgeted::kNo, data.get());
} else {
GrSurfaceDesc desc;