Reland "Fix issues with MTLPixelFormatBGR10A2Unorm on older OSes."

This is a reland of e931b838d3

Original change's description:
> Fix issues with MTLPixelFormatBGR10A2Unorm on older OSes.
>
> MTLPixelFormatBGR10A2Unorm isn't supported on older MacOS or iOS
> versions, but we still want to build those. This CL adds some
> availability checks, and works around array initialization by using a
> internally defined constant.
>
> Bug: skia:11160
> Change-Id: Ife04b0a467a5e0aa27f081cabb1936c5771b5679
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/352742
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>

Bug: skia:11160
Change-Id: I0d39bab3edeeb50315251be68744ac71ef7c194e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353077
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Jim Van Verth 2021-01-12 13:17:18 -05:00 committed by Skia Commit-Bot
parent 4b7fdc493e
commit 73032ff974

View File

@ -479,6 +479,10 @@ void GrMtlCaps::initShaderCaps() {
shaderCaps->fMaxFragmentSamplers = 16;
}
// Define this so we can use it to initialize arrays and work around
// the fact that MTLPixelFormatBGR10A2Unorm is not always available.
#define kMTLPixelFormatBGR10A2Unorm MTLPixelFormat(94)
// These are all the valid MTLPixelFormats that we support in Skia. They are roughly ordered from
// most frequently used to least to improve look up times in arrays.
static constexpr MTLPixelFormat kMtlFormats[] = {
@ -494,8 +498,7 @@ static constexpr MTLPixelFormat kMtlFormats[] = {
MTLPixelFormatRG8Unorm,
MTLPixelFormatRGB10A2Unorm,
#ifdef SK_BUILD_FOR_MAC
// BGR10_A2 wasn't added until iOS 11
MTLPixelFormatBGR10A2Unorm,
kMTLPixelFormatBGR10A2Unorm,
#endif
#ifdef SK_BUILD_FOR_IOS
MTLPixelFormatABGR4Unorm,
@ -558,6 +561,10 @@ size_t GrMtlCaps::GetFormatIndex(MTLPixelFormat pixelFormat) {
void GrMtlCaps::initFormatTable() {
FormatInfo* info;
if (@available(macos 10.13, ios 11.0, *)) {
SkASSERT(kMTLPixelFormatBGR10A2Unorm == MTLPixelFormatBGR10A2Unorm);
}
// Format: R8Unorm
{
info = &fFormatTable[GetFormatIndex(MTLPixelFormatR8Unorm)];
@ -717,7 +724,7 @@ void GrMtlCaps::initFormatTable() {
#ifdef SK_BUILD_FOR_MAC
// Format: BGR10A2Unorm
{
if (@available(macos 10.13, ios 11.0, *)) {
info = &fFormatTable[GetFormatIndex(MTLPixelFormatBGR10A2Unorm)];
if (this->isMac() && fFamilyGroup == 1) {
info->fFlags = FormatInfo::kTexturable_Flag;
@ -880,7 +887,9 @@ void GrMtlCaps::initFormatTable() {
this->setColorType(GrColorType::kBGRA_8888, { MTLPixelFormatBGRA8Unorm });
this->setColorType(GrColorType::kRGBA_1010102, { MTLPixelFormatRGB10A2Unorm });
#ifdef SK_BUILD_FOR_MAC
this->setColorType(GrColorType::kBGRA_1010102, { MTLPixelFormatBGR10A2Unorm });
if (@available(macos 10.13, ios 11.0, *)) {
this->setColorType(GrColorType::kBGRA_1010102, { MTLPixelFormatBGR10A2Unorm });
}
#endif
this->setColorType(GrColorType::kGray_8, { MTLPixelFormatR8Unorm });
this->setColorType(GrColorType::kAlpha_F16, { MTLPixelFormatR16Float });
@ -1126,7 +1135,7 @@ std::vector<GrCaps::TestFormatColorTypeCombination> GrMtlCaps::getTestingCombina
{ GrColorType::kBGRA_8888, GrBackendFormat::MakeMtl(MTLPixelFormatBGRA8Unorm) },
{ GrColorType::kRGBA_1010102, GrBackendFormat::MakeMtl(MTLPixelFormatRGB10A2Unorm) },
#ifdef SK_BUILD_FOR_MAC
{ GrColorType::kBGRA_1010102, GrBackendFormat::MakeMtl(MTLPixelFormatBGR10A2Unorm) },
{ GrColorType::kBGRA_1010102, GrBackendFormat::MakeMtl(kMTLPixelFormatBGR10A2Unorm) },
#endif
{ GrColorType::kGray_8, GrBackendFormat::MakeMtl(MTLPixelFormatR8Unorm) },
{ GrColorType::kAlpha_F16, GrBackendFormat::MakeMtl(MTLPixelFormatR16Float) },