[M83 cherry-pick] Add BGR_10A2 support to Ganesh
Here are the original Skia CLs combined in this one:
https://skia-review.googlesource.com/c/skia/+/286036 (Add BGR_10A2 support to Ganesh (take 2))
https://skia-review.googlesource.com/c/skia/+/286878 (Disable MTLPixelFormatBGR10A2Unorm on iOS)
Bug: 1068416
Change-Id: I2b63f29d40546a691b1f79571e5358447fc43775
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/285830
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/gm/wacky_yuv_formats.cpp b/gm/wacky_yuv_formats.cpp
index 54759b6..c379736 100644
--- a/gm/wacky_yuv_formats.cpp
+++ b/gm/wacky_yuv_formats.cpp
@@ -1054,6 +1054,7 @@
case VK_FORMAT_R8G8B8A8_UNORM: return kRGBA_8888_SkColorType;
case VK_FORMAT_B8G8R8A8_UNORM: return kBGRA_8888_SkColorType;
case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return kRGBA_1010102_SkColorType;
+ case VK_FORMAT_A2R10G10B10_UNORM_PACK32: return kBGRA_1010102_SkColorType;
case VK_FORMAT_R16_SFLOAT: return kA16_float_SkColorType;
case VK_FORMAT_R16G16_SFLOAT: return kR16G16_float_SkColorType;
case VK_FORMAT_R16_UNORM: return kA16_unorm_SkColorType;
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index 33fed22..bdd2060 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -778,6 +778,7 @@
kRG_88,
kBGRA_8888,
kRGBA_1010102,
+ kBGRA_1010102,
kGray_8,
kAlpha_F16,
kRGBA_F16,
@@ -822,6 +823,7 @@
case GrColorType::kRG_88: return kR8G8_unorm_SkColorType;
case GrColorType::kBGRA_8888: return kBGRA_8888_SkColorType;
case GrColorType::kRGBA_1010102: return kRGBA_1010102_SkColorType;
+ case GrColorType::kBGRA_1010102: return kBGRA_1010102_SkColorType;
case GrColorType::kGray_8: return kGray_8_SkColorType;
case GrColorType::kAlpha_F16: return kA16_float_SkColorType;
case GrColorType::kRGBA_F16: return kRGBA_F16_SkColorType;
@@ -857,7 +859,7 @@
case kRGBA_F16_SkColorType: return GrColorType::kRGBA_F16;
case kRGBA_1010102_SkColorType: return GrColorType::kRGBA_1010102;
case kRGB_101010x_SkColorType: return GrColorType::kUnknown;
- case kBGRA_1010102_SkColorType: return GrColorType::kUnknown;
+ case kBGRA_1010102_SkColorType: return GrColorType::kBGRA_1010102;
case kBGR_101010x_SkColorType: return GrColorType::kUnknown;
case kRGBA_F32_SkColorType: return GrColorType::kRGBA_F32;
case kR8G8_unorm_SkColorType: return GrColorType::kRG_88;
@@ -888,6 +890,7 @@
case GrColorType::kRG_88: return kRG_SkColorChannelFlags;
case GrColorType::kBGRA_8888: return kRGBA_SkColorChannelFlags;
case GrColorType::kRGBA_1010102: return kRGBA_SkColorChannelFlags;
+ case GrColorType::kBGRA_1010102: return kRGBA_SkColorChannelFlags;
case GrColorType::kGray_8: return kGray_SkColorChannelFlag;
case GrColorType::kAlpha_F16: return kAlpha_SkColorChannelFlag;
case GrColorType::kRGBA_F16: return kRGBA_SkColorChannelFlags;
@@ -1020,6 +1023,8 @@
return GrColorTypeDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
case GrColorType::kRGBA_1010102:
return GrColorTypeDesc::MakeRGBA(10, 2, GrColorTypeEncoding::kUnorm);
+ case GrColorType::kBGRA_1010102:
+ return GrColorTypeDesc::MakeRGBA(10, 2, GrColorTypeEncoding::kUnorm);
case GrColorType::kGray_8:
return GrColorTypeDesc::MakeGray(8, GrColorTypeEncoding::kUnorm);
case GrColorType::kAlpha_F16:
@@ -1098,6 +1103,7 @@
case GrColorType::kRG_88: return 2;
case GrColorType::kBGRA_8888: return 4;
case GrColorType::kRGBA_1010102: return 4;
+ case GrColorType::kBGRA_1010102: return 4;
case GrColorType::kGray_8: return 1;
case GrColorType::kAlpha_F16: return 2;
case GrColorType::kRGBA_F16: return 8;
@@ -1189,6 +1195,7 @@
case GrColorType::kRG_88: return "kRG_88";
case GrColorType::kBGRA_8888: return "kBGRA_8888";
case GrColorType::kRGBA_1010102: return "kRGBA_1010102";
+ case GrColorType::kBGRA_1010102: return "kBGRA_1010102";
case GrColorType::kGray_8: return "kGray_8";
case GrColorType::kAlpha_F16: return "kAlpha_F16";
case GrColorType::kRGBA_F16: return "kRGBA_F16";
diff --git a/src/gpu/GrDataUtils.cpp b/src/gpu/GrDataUtils.cpp
index 6efa24d..a6102fd 100644
--- a/src/gpu/GrDataUtils.cpp
+++ b/src/gpu/GrDataUtils.cpp
@@ -334,6 +334,9 @@
case GrColorType::kRGBA_8888: *load = SkRasterPipeline::load_8888; break;
case GrColorType::kRG_88: *load = SkRasterPipeline::load_rg88; break;
case GrColorType::kRGBA_1010102: *load = SkRasterPipeline::load_1010102; break;
+ case GrColorType::kBGRA_1010102: *load = SkRasterPipeline::load_1010102;
+ swizzle = GrSwizzle("bgra");
+ break;
case GrColorType::kAlpha_F16: *load = SkRasterPipeline::load_af16; break;
case GrColorType::kRGBA_F16_Clamped: *load = SkRasterPipeline::load_f16; break;
case GrColorType::kRG_1616: *load = SkRasterPipeline::load_rg1616; break;
@@ -396,6 +399,9 @@
case GrColorType::kRGBA_8888: *store = SkRasterPipeline::store_8888; break;
case GrColorType::kRG_88: *store = SkRasterPipeline::store_rg88; break;
case GrColorType::kRGBA_1010102: *store = SkRasterPipeline::store_1010102; break;
+ case GrColorType::kBGRA_1010102: swizzle = GrSwizzle("bgra");
+ *store = SkRasterPipeline::store_1010102;
+ break;
case GrColorType::kRGBA_F16_Clamped: *store = SkRasterPipeline::store_f16; break;
case GrColorType::kRG_1616: *store = SkRasterPipeline::store_rg1616; break;
case GrColorType::kRGBA_16161616: *store = SkRasterPipeline::store_16161616; break;
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 5f30567..72806b2 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -228,6 +228,7 @@
case GrColorType::kABGR_4444:
case GrColorType::kBGRA_8888:
case GrColorType::kRGBA_1010102:
+ case GrColorType::kBGRA_1010102:
case GrColorType::kRGBA_F16:
case GrColorType::kRGBA_F16_Clamped:
return GrColorType::kRGBA_8888;
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 05f7d6d..71075ca 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -205,6 +205,7 @@
case GrColorType::kRG_F16:
case GrColorType::kRGBA_8888_SRGB:
case GrColorType::kRGBA_1010102:
+ case GrColorType::kBGRA_1010102:
case GrColorType::kAlpha_F16:
case GrColorType::kRGBA_F32:
case GrColorType::kRGBA_F16:
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index a0f7957..89d17d5 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -1857,7 +1857,7 @@
info.fInternalFormatForTexImageOrStorage = bgraTexImageFormat;
}
- if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) {
+ if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
@@ -2451,6 +2451,7 @@
ctxInfo.hasExtension("GL_EXT_texture_type_2_10_10_10_REV")) {
info.fFlags = FormatInfo::kTexturable_Flag;
} // No WebGL support
+
if (texStorageSupported) {
info.fFlags |= FormatInfo::kUseTexStorage_Flag;
info.fInternalFormatForTexImageOrStorage = GR_GL_RGB10_A2;
@@ -2459,8 +2460,11 @@
texImageSupportsSizedInternalFormat ? GR_GL_RGB10_A2 : GR_GL_RGBA;
}
- if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) {
- info.fColorTypeInfoCount = 1;
+ if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
+ bool supportsBGRAColorType = GR_IS_GR_GL(standard) &&
+ (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra"));
+
+ info.fColorTypeInfoCount = supportsBGRAColorType ? 2 : 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: RGB10_A2, Surface: kRGBA_1010102
@@ -2495,6 +2499,40 @@
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
+ //------------------------------------------------------------------
+ // Format: RGB10_A2, Surface: kBGRA_1010102
+ if (supportsBGRAColorType) {
+ auto& ctInfo = info.fColorTypeInfos[ctIdx++];
+ ctInfo.fColorType = GrColorType::kBGRA_1010102;
+ ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
+ this->setColorTypeFormat(GrColorType::kBGRA_1010102, GrGLFormat::kRGB10_A2);
+
+ // External IO ColorTypes:
+ ctInfo.fExternalIOFormatCount = 2;
+ ctInfo.fExternalIOFormats.reset(
+ new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
+ int ioIdx = 0;
+ // Format: RGB10_A2, Surface: kBGRA_1010102, Data: kBGRA_1010102
+ {
+ auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
+ ioFormat.fColorType = GrColorType::kBGRA_1010102;
+ ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
+ ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
+ ioFormat.fExternalReadFormat =
+ formatWorkarounds.fDisallowBGRA8ReadPixels ? 0 : GR_GL_BGRA;
+ // Not guaranteed by ES/WebGL.
+ ioFormat.fRequiresImplementationReadQuery = !GR_IS_GR_GL(standard);
+ }
+
+ // Format: RGB10_A2, Surface: kBGRA_1010102, Data: kRGBA_8888
+ {
+ auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
+ ioFormat.fColorType = GrColorType::kRGBA_8888;
+ ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
+ ioFormat.fExternalTexImageFormat = 0;
+ ioFormat.fExternalReadFormat = GR_GL_RGBA;
+ }
+ }
}
}
@@ -4419,6 +4457,8 @@
if (GR_IS_GR_GL(fStandard)) {
combos.push_back({ GrColorType::kBGRA_8888,
GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) });
+ combos.push_back({ GrColorType::kBGRA_1010102,
+ GrBackendFormat::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D) });
} else {
SkASSERT(GR_IS_GR_GL_ES(fStandard) || GR_IS_GR_WEBGL(fStandard));
diff --git a/src/gpu/mock/GrMockCaps.cpp b/src/gpu/mock/GrMockCaps.cpp
index e0764dc..dbaf644 100644
--- a/src/gpu/mock/GrMockCaps.cpp
+++ b/src/gpu/mock/GrMockCaps.cpp
@@ -48,6 +48,8 @@
SkImage::CompressionType::kNone)},
{ GrColorType::kRGBA_1010102, GrBackendFormat::MakeMock(GrColorType::kRGBA_1010102,
SkImage::CompressionType::kNone)},
+ { GrColorType::kBGRA_1010102, GrBackendFormat::MakeMock(GrColorType::kBGRA_1010102,
+ SkImage::CompressionType::kNone)},
{ GrColorType::kGray_8, GrBackendFormat::MakeMock(GrColorType::kGray_8,
SkImage::CompressionType::kNone)},
{ GrColorType::kAlpha_F16, GrBackendFormat::MakeMock(GrColorType::kAlpha_F16,
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index e5be2cc..899ffe7 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -161,7 +161,7 @@
#ifdef SK_BUILD_FOR_IOS
static constexpr size_t kNumMtlFormats = 17;
#else
- static constexpr size_t kNumMtlFormats = 15;
+ static constexpr size_t kNumMtlFormats = 16;
#endif
static size_t GetFormatIndex(MTLPixelFormat);
FormatInfo fFormatTable[kNumMtlFormats];
diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm
index cd2051e..6e5edde 100644
--- a/src/gpu/mtl/GrMtlCaps.mm
+++ b/src/gpu/mtl/GrMtlCaps.mm
@@ -464,6 +464,10 @@
MTLPixelFormatR16Float,
MTLPixelFormatRG8Unorm,
MTLPixelFormatRGB10A2Unorm,
+#ifdef SK_BUILD_FOR_MAC
+ // BGR10_A2 wasn't added until iOS 11
+ MTLPixelFormatBGR10A2Unorm,
+#endif
#ifdef SK_BUILD_FOR_IOS
MTLPixelFormatABGR4Unorm,
#endif
@@ -692,6 +696,28 @@
}
}
+#ifdef SK_BUILD_FOR_MAC
+ // Format: BGR10A2Unorm
+ {
+ info = &fFormatTable[GetFormatIndex(MTLPixelFormatBGR10A2Unorm)];
+ if (this->isMac() && fFamilyGroup == 1) {
+ info->fFlags = FormatInfo::kTexturable_Flag;
+ } else {
+ info->fFlags = FormatInfo::kAllFlags;
+ }
+ info->fBytesPerPixel = 4;
+ info->fColorTypeInfoCount = 1;
+ info->fColorTypeInfos.reset(new ColorTypeInfo[info->fColorTypeInfoCount]());
+ int ctIdx = 0;
+ // Format: BGR10A2Unorm, Surface: kBGRA_1010102
+ {
+ auto& ctInfo = info->fColorTypeInfos[ctIdx++];
+ ctInfo.fColorType = GrColorType::kBGRA_1010102;
+ ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
+ }
+ }
+#endif
+
// Format: R16Float
{
info = &fFormatTable[GetFormatIndex(MTLPixelFormatR16Float)];
@@ -841,6 +867,9 @@
this->setColorType(GrColorType::kRG_88, { MTLPixelFormatRG8Unorm });
this->setColorType(GrColorType::kBGRA_8888, { MTLPixelFormatBGRA8Unorm });
this->setColorType(GrColorType::kRGBA_1010102, { MTLPixelFormatRGB10A2Unorm });
+#ifdef SK_BUILD_FOR_MAC
+ this->setColorType(GrColorType::kBGRA_1010102, { MTLPixelFormatBGR10A2Unorm });
+#endif
this->setColorType(GrColorType::kGray_8, { MTLPixelFormatR8Unorm });
this->setColorType(GrColorType::kAlpha_F16, { MTLPixelFormatR16Float });
this->setColorType(GrColorType::kRGBA_F16, { MTLPixelFormatRGBA16Float });
@@ -1082,6 +1111,9 @@
{ GrColorType::kRG_88, GrBackendFormat::MakeMtl(MTLPixelFormatRG8Unorm) },
{ GrColorType::kBGRA_8888, GrBackendFormat::MakeMtl(MTLPixelFormatBGRA8Unorm) },
{ GrColorType::kRGBA_1010102, GrBackendFormat::MakeMtl(MTLPixelFormatRGB10A2Unorm) },
+#ifdef SK_BUILD_FOR_MAC
+ { GrColorType::kBGRA_1010102, GrBackendFormat::MakeMtl(MTLPixelFormatBGR10A2Unorm) },
+#endif
{ GrColorType::kGray_8, GrBackendFormat::MakeMtl(MTLPixelFormatR8Unorm) },
{ GrColorType::kAlpha_F16, GrBackendFormat::MakeMtl(MTLPixelFormatR16Float) },
{ GrColorType::kRGBA_F16, GrBackendFormat::MakeMtl(MTLPixelFormatRGBA16Float) },
diff --git a/src/gpu/mtl/GrMtlCppUtil.h b/src/gpu/mtl/GrMtlCppUtil.h
index 47c6eb5..ab06407 100644
--- a/src/gpu/mtl/GrMtlCppUtil.h
+++ b/src/gpu/mtl/GrMtlCppUtil.h
@@ -16,7 +16,7 @@
#if GR_TEST_UTILS
const char* GrMtlFormatToStr(GrMTLPixelFormat mtlFormat);
-bool GrMtlFormatIsBGRA(GrMTLPixelFormat mtlFormat);
+bool GrMtlFormatIsBGRA8(GrMTLPixelFormat mtlFormat);
#endif
#endif
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index cc052d1..5b8f00f 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -760,6 +760,9 @@
case MTLPixelFormatRG8Unorm: return GrColorType::kRG_88;
case MTLPixelFormatBGRA8Unorm: return GrColorType::kBGRA_8888;
case MTLPixelFormatRGB10A2Unorm: return GrColorType::kRGBA_1010102;
+#ifdef SK_BUILD_FOR_MAC
+ case MTLPixelFormatBGR10A2Unorm: return GrColorType::kBGRA_1010102;
+#endif
case MTLPixelFormatR16Float: return GrColorType::kR_F16;
case MTLPixelFormatRGBA16Float: return GrColorType::kRGBA_F16;
case MTLPixelFormatR16Unorm: return GrColorType::kR_16;
diff --git a/src/gpu/mtl/GrMtlUtil.mm b/src/gpu/mtl/GrMtlUtil.mm
index 2bb6889..df03dca 100644
--- a/src/gpu/mtl/GrMtlUtil.mm
+++ b/src/gpu/mtl/GrMtlUtil.mm
@@ -263,7 +263,7 @@
}
#if GR_TEST_UTILS
-bool GrMtlFormatIsBGRA(GrMTLPixelFormat mtlFormat) {
+bool GrMtlFormatIsBGRA8(GrMTLPixelFormat mtlFormat) {
return mtlFormat == MTLPixelFormatBGRA8Unorm;
}
@@ -281,6 +281,9 @@
case MTLPixelFormatR16Float: return "R16Float";
case MTLPixelFormatRG8Unorm: return "RG8Unorm";
case MTLPixelFormatRGB10A2Unorm: return "RGB10A2Unorm";
+#ifdef SK_BUILD_FOR_MAC
+ case MTLPixelFormatBGR10A2Unorm: return "BGR10A2Unorm";
+#endif
#ifdef SK_BUILD_FOR_IOS
case MTLPixelFormatABGR4Unorm: return "ABGR4Unorm";
#endif
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index add08bc..eefeae4 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -88,6 +88,7 @@
case VK_FORMAT_B8G8R8A8_UNORM:
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
+ case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
case VK_FORMAT_R8G8B8A8_SRGB:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16_SFLOAT:
@@ -680,6 +681,7 @@
VK_FORMAT_R8G8B8_UNORM,
VK_FORMAT_R8G8_UNORM,
VK_FORMAT_A2B10G10R10_UNORM_PACK32,
+ VK_FORMAT_A2R10G10B10_UNORM_PACK32,
VK_FORMAT_B4G4R4A4_UNORM_PACK16,
VK_FORMAT_R4G4B4A4_UNORM_PACK16,
VK_FORMAT_R8G8B8A8_SRGB,
@@ -949,6 +951,25 @@
}
}
}
+ // Format: VK_FORMAT_A2R10G10B10_UNORM_PACK32
+ {
+ constexpr VkFormat format = VK_FORMAT_A2R10G10B10_UNORM_PACK32;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
+ info.fBytesPerPixel = 4;
+ if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
+ info.fColorTypeInfoCount = 1;
+ info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
+ int ctIdx = 0;
+ // Format: VK_FORMAT_A2R10G10B10_UNORM_PACK32, Surface: kBGRA_1010102
+ {
+ constexpr GrColorType ct = GrColorType::kBGRA_1010102;
+ auto& ctInfo = info.fColorTypeInfos[ctIdx++];
+ ctInfo.fColorType = ct;
+ ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
+ }
+ }
+ }
// Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16
{
constexpr VkFormat format = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
@@ -1177,6 +1198,7 @@
this->setColorType(GrColorType::kRG_88, { VK_FORMAT_R8G8_UNORM });
this->setColorType(GrColorType::kBGRA_8888, { VK_FORMAT_B8G8R8A8_UNORM });
this->setColorType(GrColorType::kRGBA_1010102, { VK_FORMAT_A2B10G10R10_UNORM_PACK32 });
+ this->setColorType(GrColorType::kBGRA_1010102, { VK_FORMAT_A2R10G10B10_UNORM_PACK32 });
this->setColorType(GrColorType::kGray_8, { VK_FORMAT_R8_UNORM });
this->setColorType(GrColorType::kAlpha_F16, { VK_FORMAT_R16_SFLOAT });
this->setColorType(GrColorType::kRGBA_F16, { VK_FORMAT_R16G16B16A16_SFLOAT });
@@ -1539,6 +1561,7 @@
case VK_FORMAT_R8G8_UNORM: return GrColorType::kRG_88;
case VK_FORMAT_B8G8R8A8_UNORM: return GrColorType::kBGRA_8888;
case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102;
+ case VK_FORMAT_A2R10G10B10_UNORM_PACK32: return GrColorType::kBGRA_1010102;
case VK_FORMAT_R16_UNORM: return GrColorType::kAlpha_16;
case VK_FORMAT_R16_SFLOAT: return GrColorType::kAlpha_F16;
case VK_FORMAT_R16G16_UNORM: return GrColorType::kRG_1616;
@@ -1746,7 +1769,8 @@
{ GrColorType::kRGB_888x, GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM) },
{ GrColorType::kRG_88, GrBackendFormat::MakeVk(VK_FORMAT_R8G8_UNORM) },
{ GrColorType::kBGRA_8888, GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM) },
- { GrColorType::kRGBA_1010102, GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32)},
+ { GrColorType::kRGBA_1010102, GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32)},
+ { GrColorType::kBGRA_1010102, GrBackendFormat::MakeVk(VK_FORMAT_A2R10G10B10_UNORM_PACK32)},
{ GrColorType::kGray_8, GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM) },
{ GrColorType::kAlpha_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16_SFLOAT) },
{ GrColorType::kRGBA_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT) },
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 356e151..83e904e 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -281,7 +281,7 @@
std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
int fColorTypeInfoCount = 0;
};
- static const size_t kNumVkFormats = 21;
+ static const size_t kNumVkFormats = 22;
FormatInfo fFormatTable[kNumVkFormats];
FormatInfo& getFormatInfo(VkFormat);
diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp
index 043b31b..55a5ed7 100644
--- a/src/gpu/vk/GrVkUtil.cpp
+++ b/src/gpu/vk/GrVkUtil.cpp
@@ -22,6 +22,7 @@
case VK_FORMAT_R8G8B8_UNORM: return GrColorType::kRGB_888x == colorType;
case VK_FORMAT_R8G8_UNORM: return GrColorType::kRG_88 == colorType;
case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return GrColorType::kRGBA_1010102 == colorType;
+ case VK_FORMAT_A2R10G10B10_UNORM_PACK32: return GrColorType::kBGRA_1010102 == colorType;
case VK_FORMAT_R5G6B5_UNORM_PACK16: return GrColorType::kBGR_565 == colorType;
// R4G4B4A4 is not required to be supported so we actually
// store RGBA_4444 data as B4G4R4A4.
@@ -56,6 +57,7 @@
case VK_FORMAT_R8G8B8_UNORM:
case VK_FORMAT_R8G8_UNORM:
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
+ case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
case VK_FORMAT_R5G6B5_UNORM_PACK16:
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
diff --git a/src/gpu/vk/GrVkUtil.h b/src/gpu/vk/GrVkUtil.h
index 72b37e9..946b3d1 100644
--- a/src/gpu/vk/GrVkUtil.h
+++ b/src/gpu/vk/GrVkUtil.h
@@ -97,6 +97,7 @@
case VK_FORMAT_R8G8B8_UNORM: return "R8G8B8_UNORM";
case VK_FORMAT_R8G8_UNORM: return "R8G8_UNORM";
case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return "A2B10G10R10_UNORM_PACK32";
+ case VK_FORMAT_A2R10G10B10_UNORM_PACK32: return "A2R10G10B10_UNORM_PACK32";
case VK_FORMAT_B4G4R4A4_UNORM_PACK16: return "B4G4R4A4_UNORM_PACK16";
case VK_FORMAT_R4G4B4A4_UNORM_PACK16: return "R4G4B4A4_UNORM_PACK16";
case VK_FORMAT_R32G32B32A32_SFLOAT: return "R32G32B32A32_SFLOAT";
diff --git a/tests/BackendAllocationTest.cpp b/tests/BackendAllocationTest.cpp
index 7b4be8b..7c4936f 100644
--- a/tests/BackendAllocationTest.cpp
+++ b/tests/BackendAllocationTest.cpp
@@ -64,8 +64,8 @@
skColorType,
nullptr, nullptr);
if (!surf) {
- ERRORF(reporter, "Couldn't make surface from backendTexture for colorType %d\n",
- skColorType);
+ ERRORF(reporter, "Couldn't make surface from backendTexture for %s\n",
+ ToolUtils::colortype_name(skColorType));
} else {
REPORTER_ASSERT(reporter, initialCount+1 == cache->getResourceCount());
}
@@ -79,8 +79,8 @@
kPremul_SkAlphaType,
nullptr);
if (!img) {
- ERRORF(reporter, "Couldn't make image from backendTexture for skColorType %d\n",
- skColorType);
+ ERRORF(reporter, "Couldn't make image from backendTexture for %s\n",
+ ToolUtils::colortype_name(skColorType));
} else {
SkImage_Base* ib = as_IB(img);
@@ -100,7 +100,7 @@
context->deleteBackendTexture(backendTex);
}
-static bool isBGRA(const GrBackendFormat& format) {
+static bool isBGRA8(const GrBackendFormat& format) {
switch (format.backend()) {
case GrBackendApi::kOpenGL:
#ifdef SK_GL
@@ -119,7 +119,7 @@
}
case GrBackendApi::kMetal:
#ifdef SK_METAL
- return GrMtlFormatIsBGRA(format.asMtlFormat());
+ return GrMtlFormatIsBGRA8(format.asMtlFormat());
#else
return false;
#endif
@@ -439,7 +439,7 @@
return;
}
- if (skColorType == kBGRA_8888_SkColorType && !isBGRA(backendTex.getBackendFormat())) {
+ if (skColorType == kBGRA_8888_SkColorType && !isBGRA8(backendTex.getBackendFormat())) {
// When kBGRA is backed by an RGBA something goes wrong in the swizzling
return;
}
@@ -600,11 +600,11 @@
{ kRGB_888x_SkColorType, SkColors::kCyan },
// TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul)
{ kBGRA_8888_SkColorType, { 1, 0, 0, 1.0f } },
- // TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul)
- { kRGBA_1010102_SkColorType, { .25f, .5f, .75f, 1.0f }},
- // RGB/BGR 101010x and BGRA 1010102 have no Ganesh correlate
+ // TODO: readback is busted for *10A2 when alpha = 0.5f (perhaps premul vs. unpremul)
+ { kRGBA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
+ { kBGRA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
+ // RGB/BGR 101010x have no Ganesh correlate
{ kRGB_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } },
- { kBGRA_1010102_SkColorType, { 0, 0.5f, 0, 0.5f } },
{ kBGR_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } },
{ kGray_8_SkColorType, kGrayCol },
{ kRGBA_F16Norm_SkColorType, SkColors::kLtGray },
@@ -712,26 +712,28 @@
renderable);
}
- auto createWithSrcDataMtd = [](GrContext* context,
- const SkPixmap srcData[],
- int numLevels,
- GrRenderable renderable) {
- SkASSERT(srcData && numLevels);
- auto result = context->createBackendTexture(srcData, numLevels, renderable,
- GrProtected::kNo);
- check_vk_layout(result, VkLayout::kReadOnlyOptimal);
+ {
+ auto createWithSrcDataMtd = [](GrContext* context,
+ const SkPixmap srcData[],
+ int numLevels,
+ GrRenderable renderable) {
+ SkASSERT(srcData && numLevels);
+ auto result = context->createBackendTexture(srcData, numLevels, renderable,
+ GrProtected::kNo);
+ check_vk_layout(result, VkLayout::kReadOnlyOptimal);
#ifdef SK_DEBUG
- {
- auto format =
- context->defaultBackendFormat(srcData[0].colorType(), renderable);
- SkASSERT(format == result.getBackendFormat());
- }
+ {
+ auto format = context->defaultBackendFormat(srcData[0].colorType(),
+ renderable);
+ SkASSERT(format == result.getBackendFormat());
+ }
#endif
- return result;
- };
+ return result;
+ };
- test_pixmap_init(context, reporter, createWithSrcDataMtd, colorType, mipMapped,
- renderable);
+ test_pixmap_init(context, reporter, createWithSrcDataMtd, colorType, mipMapped,
+ renderable);
+ }
}
}
}
@@ -763,7 +765,8 @@
{ GrColorType::kBGRA_8888, GR_GL_RGBA8, SkColors::kBlue },
{ GrColorType::kBGRA_8888, GR_GL_BGRA8, SkColors::kBlue },
// TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul)
- { GrColorType::kRGBA_1010102, GR_GL_RGB10_A2, { 0.5f, 0, 0, 1.0f } },
+ { GrColorType::kRGBA_1010102, GR_GL_RGB10_A2, { 0.25f, 0.5f, 0.75f, 1.f }},
+ { GrColorType::kBGRA_1010102, GR_GL_RGB10_A2, { 0.25f, 0.5f, 0.75f, 1.f }},
{ GrColorType::kBGR_565, GR_GL_RGB565, SkColors::kRed },
{ GrColorType::kABGR_4444, GR_GL_RGBA4, SkColors::kGreen },
@@ -796,9 +799,11 @@
continue;
}
- if (GrColorType::kBGRA_8888 == combo.fColorType) {
- // We allow using a GL_RGBA8 texture as BGRA on desktop GL but not ES.
- if (GR_GL_RGBA8 == combo.fFormat && kGL_GrGLStandard != standard) {
+ if (GrColorType::kBGRA_8888 == combo.fColorType ||
+ GrColorType::kBGRA_1010102 == combo.fColorType) {
+ // We allow using a GL_RGBA8 or GR_GL_RGB10_A2 texture as BGRA on desktop GL but not ES
+ if (kGL_GrGLStandard != standard &&
+ (GR_GL_RGBA8 == combo.fFormat || GR_GL_RGB10_A2 == combo.fFormat)) {
continue;
}
}
@@ -914,7 +919,10 @@
{ GrColorType::kBGRA_8888, VK_FORMAT_B8G8R8A8_UNORM, SkColors::kBlue },
- { GrColorType::kRGBA_1010102, VK_FORMAT_A2B10G10R10_UNORM_PACK32, { 0.5f, 0, 0, 1.0f }},
+ { GrColorType::kRGBA_1010102, VK_FORMAT_A2B10G10R10_UNORM_PACK32,
+ { 0.25f, 0.5f, 0.75f, 1.0f }},
+ { GrColorType::kBGRA_1010102, VK_FORMAT_A2R10G10B10_UNORM_PACK32,
+ { 0.25f, 0.5f, 0.75f, 1.0f }},
{ GrColorType::kBGR_565, VK_FORMAT_R5G6B5_UNORM_PACK16, SkColors::kRed },
{ GrColorType::kABGR_4444, VK_FORMAT_R4G4B4A4_UNORM_PACK16, SkColors::kCyan },
diff --git a/tests/MtlBackendAllocationTest.mm b/tests/MtlBackendAllocationTest.mm
index f7ea5b5..aafa320 100644
--- a/tests/MtlBackendAllocationTest.mm
+++ b/tests/MtlBackendAllocationTest.mm
@@ -49,7 +49,12 @@
{ GrColorType::kBGRA_8888, MTLPixelFormatBGRA8Unorm, SkColors::kBlue },
- { GrColorType::kRGBA_1010102, MTLPixelFormatRGB10A2Unorm, { 0.5f, 0, 0, 1.0f } },
+ { GrColorType::kRGBA_1010102, MTLPixelFormatRGB10A2Unorm,
+ { 0.25f, 0.5f, 0.75f, 1.0f } },
+#ifdef SK_BUILD_FOR_MAC
+ { GrColorType::kBGRA_1010102, MTLPixelFormatBGR10A2Unorm,
+ { 0.25f, 0.5f, 0.75f, 1.0f } },
+#endif
#ifdef SK_BUILD_FOR_IOS
{ GrColorType::kBGR_565, MTLPixelFormatB5G6R5Unorm, SkColors::kRed },
{ GrColorType::kABGR_4444, MTLPixelFormatABGR4Unorm, SkColors::kGreen },
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index 3c7fac3..df18ab9 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -31,8 +31,9 @@
for (int x = 0; x < w; ++x) {
uint8_t a = actual[y * actualRowBytes + x];
uint8_t e = expected[y * w + x];
- if (GrColorType::kRGBA_1010102 == colorType) {
- // This config only preserves two bits of alpha
+ if (GrColorType::kRGBA_1010102 == colorType ||
+ GrColorType::kBGRA_1010102 == colorType) {
+ // These configs only preserves two bits of alpha
a >>= 6;
e >>= 6;
}
diff --git a/tests/TransferPixelsTest.cpp b/tests/TransferPixelsTest.cpp
index 69f4120..e3bedd5 100644
--- a/tests/TransferPixelsTest.cpp
+++ b/tests/TransferPixelsTest.cpp
@@ -182,8 +182,9 @@
auto error = std::function<ComparePixmapsErrorReporter>(
[reporter, colorType](int x, int y, const float diffs[4]) {
ERRORF(reporter,
- "Error at (%d %d) in transfer, color type: %d, diffs: (%f, %f, %f, %f)", x,
- y, colorType, diffs[0], diffs[1], diffs[2], diffs[3]);
+ "Error at (%d %d) in transfer, color type: %s, diffs: (%f, %f, %f, %f)",
+ x, y, GrColorTypeToStr(colorType),
+ diffs[0], diffs[1], diffs[2], diffs[3]);
});
GrImageInfo srcInfo(allowedSrc.fColorType, kUnpremul_SkAlphaType, nullptr, tex->width(),
tex->height());
@@ -355,8 +356,9 @@
auto error = std::function<ComparePixmapsErrorReporter>(
[reporter, colorType](int x, int y, const float diffs[4]) {
ERRORF(reporter,
- "Error at (%d %d) in transfer, color type: %d, diffs: (%f, %f, %f, %f)", x,
- y, colorType, diffs[0], diffs[1], diffs[2], diffs[3]);
+ "Error at (%d %d) in transfer, color type: %s, diffs: (%f, %f, %f, %f)",
+ x, y, GrColorTypeToStr(colorType),
+ diffs[0], diffs[1], diffs[2], diffs[3]);
});
GrImageInfo textureDataInfo(colorType, kUnpremul_SkAlphaType, nullptr, kTexDims);
ComparePixels(textureDataInfo, textureData.get(), textureDataRowBytes, transferInfo,
@@ -416,6 +418,7 @@
GrColorType::kRG_88,
GrColorType::kBGRA_8888,
GrColorType::kRGBA_1010102,
+ GrColorType::kBGRA_1010102,
GrColorType::kGray_8,
GrColorType::kAlpha_F16,
GrColorType::kRGBA_F16,
@@ -448,6 +451,7 @@
GrColorType::kRG_88,
GrColorType::kBGRA_8888,
GrColorType::kRGBA_1010102,
+ GrColorType::kBGRA_1010102,
GrColorType::kGray_8,
GrColorType::kAlpha_F16,
GrColorType::kRGBA_F16,
diff --git a/tools/ToolUtils.cpp b/tools/ToolUtils.cpp
index b41e985..027f8f8 100644
--- a/tools/ToolUtils.cpp
+++ b/tools/ToolUtils.cpp
@@ -58,8 +58,8 @@
case kRGB_888x_SkColorType: return "RGB_888x";
case kBGRA_8888_SkColorType: return "BGRA_8888";
case kRGBA_1010102_SkColorType: return "RGBA_1010102";
- case kRGB_101010x_SkColorType: return "RGB_101010x";
case kBGRA_1010102_SkColorType: return "BGRA_1010102";
+ case kRGB_101010x_SkColorType: return "RGB_101010x";
case kBGR_101010x_SkColorType: return "BGR_101010x";
case kGray_8_SkColorType: return "Gray_8";
case kRGBA_F16Norm_SkColorType: return "RGBA_F16Norm";
@@ -86,8 +86,8 @@
case kRGB_888x_SkColorType: return "888";
case kBGRA_8888_SkColorType: return "8888";
case kRGBA_1010102_SkColorType: return "1010102";
- case kRGB_101010x_SkColorType: return "101010";
case kBGRA_1010102_SkColorType: return "1010102";
+ case kRGB_101010x_SkColorType: return "101010";
case kBGR_101010x_SkColorType: return "101010";
case kGray_8_SkColorType: return "G8";
case kRGBA_F16Norm_SkColorType: return "F16Norm"; // TODO: "F16"?