From 8225484e3fbec554e9efcdc716aef2b76c7c6b55 Mon Sep 17 00:00:00 2001 From: xu Date: Tue, 16 Aug 2022 20:23:01 +0800 Subject: [PATCH] skia astc support Signed-off-by: xu --- engine/flutter/lib/ui/painting/image.h | 11 +++++++++++ skia/include/core/SkImage.h | 3 ++- skia/include/gpu/gl/GrGLTypes.h | 3 ++- skia/include/private/GrTypesPriv.h | 21 ++++++++++++++++++-- skia/src/gpu/GrDataUtils.cpp | 7 +++++++ skia/src/gpu/GrGpu.cpp | 2 +- skia/src/gpu/gl/GrGLCaps.cpp | 27 +++++++++++++++++++++++++- skia/src/gpu/gl/GrGLGpu.cpp | 1 + skia/src/gpu/gl/GrGLUtil.cpp | 6 +++++- skia/src/gpu/gl/GrGLUtil.h | 3 +++ 10 files changed, 77 insertions(+), 7 deletions(-) diff --git a/engine/flutter/lib/ui/painting/image.h b/engine/flutter/lib/ui/painting/image.h index 516a2e5d..e2b518e1 100644 --- a/engine/flutter/lib/ui/painting/image.h +++ b/engine/flutter/lib/ui/painting/image.h @@ -43,10 +43,21 @@ class CanvasImage final : public RefCountedDartWrappable { static void RegisterNatives(tonic::DartLibraryNatives* natives); + sk_sp compressData() const { return compressData_; } + int compressWidth() { return compressWidth_; } + int compressHeight() { return compressHeight_; } + void setCompress(sk_sp data, int width, int height) { + compressData_ = data; + compressWidth_ = width; + compressHeight_ = height; + } private: CanvasImage(); flutter::SkiaGPUObject image_; + sk_sp compressData_; + int compressWidth_; + int compressHeight_; }; } // namespace flutter diff --git a/skia/include/core/SkImage.h b/skia/include/core/SkImage.h index 88b16858..23beb518 100644 --- a/skia/include/core/SkImage.h +++ b/skia/include/core/SkImage.h @@ -228,7 +228,8 @@ public: // Experimental enum CompressionType { kETC1_CompressionType, - kLast_CompressionType = kETC1_CompressionType, + kASTC_CompressionType, + kLast_CompressionType = kASTC_CompressionType, }; /** Creates a GPU-backed SkImage from compressed data. diff --git a/skia/include/gpu/gl/GrGLTypes.h b/skia/include/gpu/gl/GrGLTypes.h index b1cb6d10..dfdea7ef 100644 --- a/skia/include/gpu/gl/GrGLTypes.h +++ b/skia/include/gpu/gl/GrGLTypes.h @@ -79,8 +79,9 @@ enum class GrGLFormat { kRGBA16, kRG16F, kLUMINANCE16F, + kCOMPRESSED_ASTC_RGB8, - kLast = kLUMINANCE16F + kLast = kCOMPRESSED_ASTC_RGB8 }; /////////////////////////////////////////////////////////////////////////////// diff --git a/skia/include/private/GrTypesPriv.h b/skia/include/private/GrTypesPriv.h index 8485817d..5e82706e 100644 --- a/skia/include/private/GrTypesPriv.h +++ b/skia/include/private/GrTypesPriv.h @@ -67,8 +67,8 @@ enum GrPixelConfig { // Experimental (for Y416 and mutant P016/P010) kRGBA_16161616_GrPixelConfig, kRG_half_GrPixelConfig, - - kLast_GrPixelConfig = kRG_half_GrPixelConfig + kRGB_ASTC_GrPixelConfig, + kLast_GrPixelConfig = kRGB_ASTC_GrPixelConfig }; static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1; @@ -838,6 +838,7 @@ static constexpr bool GrPixelConfigIsSRGB(GrPixelConfig config) { case kRGBA_half_GrPixelConfig: case kRGBA_half_Clamped_GrPixelConfig: case kRGB_ETC1_GrPixelConfig: + case kRGB_ASTC_GrPixelConfig: case kR_16_GrPixelConfig: case kRG_1616_GrPixelConfig: // Experimental (for Y416 and mutant P016/P010) @@ -851,6 +852,7 @@ static constexpr bool GrPixelConfigIsSRGB(GrPixelConfig config) { static constexpr GrPixelConfig GrCompressionTypePixelConfig(SkImage::CompressionType compression) { switch (compression) { case SkImage::kETC1_CompressionType: return kRGB_ETC1_GrPixelConfig; + case SkImage::kASTC_CompressionType: return kRGB_ASTC_GrPixelConfig; } SkUNREACHABLE; } @@ -887,6 +889,7 @@ static constexpr size_t GrBytesPerPixel(GrPixelConfig config) { return 16; case kUnknown_GrPixelConfig: case kRGB_ETC1_GrPixelConfig: + case kRGB_ASTC_GrPixelConfig: return 0; // Experimental (for Y416 and mutant P016/P010) @@ -908,6 +911,7 @@ static constexpr bool GrPixelConfigIsOpaque(GrPixelConfig config) { case kGray_8_as_Lum_GrPixelConfig: case kGray_8_as_Red_GrPixelConfig: case kRGB_ETC1_GrPixelConfig: + case kRGB_ASTC_GrPixelConfig: case kR_16_GrPixelConfig: case kRG_1616_GrPixelConfig: case kRG_half_GrPixelConfig: // Experimental (for mutant P016/P010) @@ -959,6 +963,7 @@ static constexpr bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) { case kRGBA_half_GrPixelConfig: case kRGBA_half_Clamped_GrPixelConfig: case kRGB_ETC1_GrPixelConfig: + case kRGB_ASTC_GrPixelConfig: case kR_16_GrPixelConfig: case kRG_1616_GrPixelConfig: // Experimental (for Y416 and mutant P016/P010) @@ -988,6 +993,7 @@ static constexpr bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) { case kSRGBA_8888_GrPixelConfig: case kRGBA_1010102_GrPixelConfig: case kRGB_ETC1_GrPixelConfig: + case kRGB_ASTC_GrPixelConfig: case kR_16_GrPixelConfig: case kRG_1616_GrPixelConfig: case kRGBA_16161616_GrPixelConfig: // Experimental (for Y416) @@ -1019,6 +1025,8 @@ static constexpr bool GrPixelConfigIsCompressed(GrPixelConfig config) { switch (config) { case kRGB_ETC1_GrPixelConfig: return true; + case kRGB_ASTC_GrPixelConfig: + return true; default: return false; } @@ -1032,6 +1040,8 @@ static constexpr GrPixelConfig GrMakePixelConfigUncompressed(GrPixelConfig confi switch (config) { case kRGB_ETC1_GrPixelConfig: return kRGBA_8888_GrPixelConfig; + case kRGB_ASTC_GrPixelConfig: + return kRGBA_8888_GrPixelConfig; default: return config; } @@ -1050,6 +1060,10 @@ static inline size_t GrCompressedFormatDataSize(GrPixelConfig config, SkASSERT((width & 3) == 0); SkASSERT((height & 3) == 0); return (width >> 2) * (height >> 2) * 8; + case kRGB_ASTC_GrPixelConfig: + SkASSERT((width & 3) == 0); + SkASSERT((height & 3) == 0); + return (width >> 2) * (height >> 2) * 8; default: SK_ABORT("Unknown compressed pixel config"); @@ -1425,6 +1439,8 @@ static constexpr GrColorType GrPixelConfigToColorType(GrPixelConfig config) { // We may need a roughly equivalent color type for a compressed texture. This should be // the logical format for decompressing the data into. return GrColorType::kRGB_888x; + case kRGB_ASTC_GrPixelConfig: + return GrColorType::kRGB_888x; case kAlpha_8_as_Alpha_GrPixelConfig: return GrColorType::kAlpha_8; case kAlpha_8_as_Red_GrPixelConfig: @@ -1548,6 +1564,7 @@ static constexpr const char* GrPixelConfigToStr(GrPixelConfig config) { case kRGBA_half_GrPixelConfig: return "RGBAHalf"; case kRGBA_half_Clamped_GrPixelConfig: return "RGBAHalfClamped"; case kRGB_ETC1_GrPixelConfig: return "RGBETC1"; + case kRGB_ASTC_GrPixelConfig: return "RGBASTC"; case kR_16_GrPixelConfig: return "R16"; case kRG_1616_GrPixelConfig: return "RG1616"; case kRGBA_16161616_GrPixelConfig: return "RGBA16161616"; diff --git a/skia/src/gpu/GrDataUtils.cpp b/skia/src/gpu/GrDataUtils.cpp index c772f73b..3c22c982 100644 --- a/skia/src/gpu/GrDataUtils.cpp +++ b/skia/src/gpu/GrDataUtils.cpp @@ -118,8 +118,15 @@ 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: + { int numBlocks = num_ETC1_blocks(width, height); return numBlocks * sizeof(ETC1Block); + } + case SkImage::kASTC_CompressionType: + { + int size = std::ceil(width / 4.0f) * std::ceil(height / 4.0f) * 16; + return size; + } } SK_ABORT("Unexpected compression type"); } diff --git a/skia/src/gpu/GrGpu.cpp b/skia/src/gpu/GrGpu.cpp index 970c7a38..fd407e23 100644 --- a/skia/src/gpu/GrGpu.cpp +++ b/skia/src/gpu/GrGpu.cpp @@ -220,7 +220,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::kETC1_CompressionType || compressionType == SkImage::kASTC_CompressionType); this->handleDirtyContext(); if (width < 1 || width > this->caps()->maxTextureSize() || diff --git a/skia/src/gpu/gl/GrGLCaps.cpp b/skia/src/gpu/gl/GrGLCaps.cpp index 81d5cca7..4cb40b26 100644 --- a/skia/src/gpu/gl/GrGLCaps.cpp +++ b/skia/src/gpu/gl/GrGLCaps.cpp @@ -2550,6 +2550,21 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa // There are no support GrColorTypes for this format } + // Format: COMPRESSED_ASTC_RGB8 + { + FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ASTC_RGB8); + info.fFormatType = FormatType::kNormalizedFixedPoint; + info.fBaseInternalFormat = GR_GL_RGB; + info.fInternalFormatForTexImage = GR_GL_COMPRESSED_RGBA_ASTC_4x4; + if (GR_IS_GR_GL_ES(standard)) { + if (ctxInfo.hasExtension("GL_OES_texture_compression_astc")) { + info.fFlags = FormatInfo::kTexturable_Flag; + } + } // No GL or WebGL support + + // There are no support GrColorTypes for this format + } + // Format: GR_GL_R16 { FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16); @@ -3748,7 +3763,8 @@ bool GrGLCaps::isFormatSRGB(const GrBackendFormat& format) const { bool GrGLCaps::isFormatCompressed(const GrBackendFormat& format) const { auto fmt = format.asGLFormat(); - return fmt == GrGLFormat::kCOMPRESSED_RGB8_ETC2 || fmt == GrGLFormat::kCOMPRESSED_ETC1_RGB8; + return fmt == GrGLFormat::kCOMPRESSED_RGB8_ETC2 || fmt == GrGLFormat::kCOMPRESSED_ETC1_RGB8 + || fmt == GrGLFormat::kCOMPRESSED_ASTC_RGB8; } bool GrGLCaps::isFormatTexturableAndUploadable(GrColorType ct, @@ -3879,6 +3895,8 @@ static GrPixelConfig validate_sized_format(GrGLFormat format, } else if (format == GrGLFormat::kCOMPRESSED_RGB8_ETC2 || format == GrGLFormat::kCOMPRESSED_ETC1_RGB8) { return kRGB_ETC1_GrPixelConfig; + } else if (format == GrGLFormat::kCOMPRESSED_ASTC_RGB8) { + return kRGB_ASTC_GrPixelConfig; } break; case GrColorType::kRG_88: @@ -4021,6 +4039,11 @@ GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType( switch (compressionType) { case SkImage::kETC1_CompressionType: return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D); + case SkImage::kASTC_CompressionType: + if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_ASTC_RGB8)) { + return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_RGBA_ASTC_4x4, GR_GL_TEXTURE_2D); + } + return {}; } SK_ABORT("Invalid compression type"); } @@ -4071,6 +4094,8 @@ std::vector GrGLCaps::getTestingCombinat GrBackendFormat::MakeGL(GR_GL_COMPRESSED_RGB8_ETC2, GR_GL_TEXTURE_2D) }, { GrColorType::kRGB_888x, GrBackendFormat::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D) }, + { GrColorType::kRGB_888x, + GrBackendFormat::MakeGL(GR_GL_COMPRESSED_RGBA_ASTC_4x4, GR_GL_TEXTURE_2D) }, { GrColorType::kRG_88, GrBackendFormat::MakeGL(GR_GL_RG8, GR_GL_TEXTURE_2D) }, { GrColorType::kRGBA_1010102, diff --git a/skia/src/gpu/gl/GrGLGpu.cpp b/skia/src/gpu/gl/GrGLGpu.cpp index 16a286bb..e20a2a63 100644 --- a/skia/src/gpu/gl/GrGLGpu.cpp +++ b/skia/src/gpu/gl/GrGLGpu.cpp @@ -3791,6 +3791,7 @@ static GrPixelConfig gl_format_to_pixel_config(GrGLFormat format) { case GrGLFormat::kCOMPRESSED_RGB8_ETC2: return kRGB_ETC1_GrPixelConfig; case GrGLFormat::kCOMPRESSED_ETC1_RGB8: return kRGB_ETC1_GrPixelConfig; + case GrGLFormat::kCOMPRESSED_ASTC_RGB8: return kRGB_ASTC_GrPixelConfig; } SkUNREACHABLE; } diff --git a/skia/src/gpu/gl/GrGLUtil.cpp b/skia/src/gpu/gl/GrGLUtil.cpp index 52e67d23..4bffdf9c 100644 --- a/skia/src/gpu/gl/GrGLUtil.cpp +++ b/skia/src/gpu/gl/GrGLUtil.cpp @@ -602,6 +602,7 @@ bool GrGLFormatIsCompressed(GrGLFormat format) { switch (format) { case GrGLFormat::kCOMPRESSED_RGB8_ETC2: case GrGLFormat::kCOMPRESSED_ETC1_RGB8: + case GrGLFormat::kCOMPRESSED_ASTC_RGB8: return true; case GrGLFormat::kRGBA8: @@ -635,7 +636,9 @@ bool GrGLFormatToCompressionType(GrGLFormat format, SkImage::CompressionType* co case GrGLFormat::kCOMPRESSED_ETC1_RGB8: *compressionType = SkImage::kETC1_CompressionType; return true; - + case GrGLFormat::kCOMPRESSED_ASTC_RGB8: + *compressionType = SkImage::kASTC_CompressionType; + return true; case GrGLFormat::kRGBA8: case GrGLFormat::kR8: case GrGLFormat::kALPHA8: @@ -696,6 +699,7 @@ size_t GrGLBytesPerFormat(GrGLFormat glFormat) { case GrGLFormat::kCOMPRESSED_RGB8_ETC2: case GrGLFormat::kCOMPRESSED_ETC1_RGB8: + case GrGLFormat::kCOMPRESSED_ASTC_RGB8: case GrGLFormat::kUnknown: return 0; } diff --git a/skia/src/gpu/gl/GrGLUtil.h b/skia/src/gpu/gl/GrGLUtil.h index d17c0282..23df337c 100644 --- a/skia/src/gpu/gl/GrGLUtil.h +++ b/skia/src/gpu/gl/GrGLUtil.h @@ -294,6 +294,7 @@ static constexpr GrGLFormat GrGLFormatFromGLEnum(GrGLenum glFormat) { case GR_GL_SRGB8_ALPHA8: return GrGLFormat::kSRGB8_ALPHA8; case GR_GL_COMPRESSED_RGB8_ETC2: return GrGLFormat::kCOMPRESSED_RGB8_ETC2; case GR_GL_COMPRESSED_ETC1_RGB8: return GrGLFormat::kCOMPRESSED_ETC1_RGB8; + case GR_GL_COMPRESSED_RGBA_ASTC_4x4: return GrGLFormat::kCOMPRESSED_ASTC_RGB8; case GR_GL_R16: return GrGLFormat::kR16; case GR_GL_RG16: return GrGLFormat::kRG16; case GR_GL_RGBA16: return GrGLFormat::kRGBA16; @@ -323,6 +324,7 @@ static constexpr GrGLenum GrGLFormatToEnum(GrGLFormat format) { case GrGLFormat::kSRGB8_ALPHA8: return GR_GL_SRGB8_ALPHA8; case GrGLFormat::kCOMPRESSED_RGB8_ETC2: return GR_GL_COMPRESSED_RGB8_ETC2; case GrGLFormat::kCOMPRESSED_ETC1_RGB8: return GR_GL_COMPRESSED_ETC1_RGB8; + case GrGLFormat::kCOMPRESSED_ASTC_RGB8: return GR_GL_COMPRESSED_RGBA_ASTC_4x4; case GrGLFormat::kR16: return GR_GL_R16; case GrGLFormat::kRG16: return GR_GL_RG16; case GrGLFormat::kRGBA16: return GR_GL_RGBA16; @@ -352,6 +354,7 @@ static constexpr const char* GrGLFormatToStr(GrGLenum glFormat) { case GR_GL_SRGB8_ALPHA8: return "SRGB8_ALPHA8"; case GR_GL_COMPRESSED_RGB8_ETC2: return "ETC2"; case GR_GL_COMPRESSED_ETC1_RGB8: return "ETC1"; + case GR_GL_COMPRESSED_RGBA_ASTC_4x4: return "ASTC"; case GR_GL_R16: return "R16"; case GR_GL_RG16: return "RG16"; case GR_GL_RGBA16: return "RGBA16"; -- Gitee