diff --git a/gm/etc1.cpp b/gm/etc1.cpp index 773ba2d6a6..f80f833d7c 100644 --- a/gm/etc1.cpp +++ b/gm/etc1.cpp @@ -69,7 +69,7 @@ protected: void onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override { sk_sp image = SkImage::MakeFromCompressed(context, fETC1Data, kTexWidth, kTexHeight, - SkImage::kETC1_CompressionType); + SkImage::CompressionType::kETC1); canvas->drawImage(image, 0, 0); } diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 108a5d059e..cc748ef3ee 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -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(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. diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h index 28a0abcfa4..c2e79c8c94 100644 --- a/include/private/GrTypesPriv.h +++ b/include/private/GrTypesPriv.h @@ -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; } /** diff --git a/src/gpu/GrDataUtils.cpp b/src/gpu/GrDataUtils.cpp index b820b7d3f9..a4753a3204 100644 --- a/src/gpu/GrDataUtils.cpp +++ b/src/gpu/GrDataUtils.cpp @@ -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); } } diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 43411bfedf..4b2aa9488d 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -276,7 +276,7 @@ sk_sp 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() || diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp index b1707beb1d..a3a1f861dc 100644 --- a/src/gpu/GrSurface.cpp +++ b/src/gpu/GrSurface.cpp @@ -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 { diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 06db07e76e..b6d69fc85a 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -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 { diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp index ae5529b252..c897310c7b 100644 --- a/src/gpu/gl/GrGLUtil.cpp +++ b/src/gpu/gl/GrGLUtil.cpp @@ -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: diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm index a5fbdef5e8..9621000432 100644 --- a/src/gpu/mtl/GrMtlCaps.mm +++ b/src/gpu/mtl/GrMtlCaps.mm @@ -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 diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 90fbd4fd8f..9465bdbf60 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -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 { diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp index 09ededc970..cd4d3a9001 100644 --- a/src/gpu/vk/GrVkUtil.cpp +++ b/src/gpu/vk/GrVkUtil.cpp @@ -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; diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 3a1026b000..adf65005be 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -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;