Fill in missing GrMtlCaps functions and fix for 0 buffer alloc.

Bug: skia:
Change-Id: I4981e49dc45d607f3f6493da67844b6dfa74a551
Reviewed-on: https://skia-review.googlesource.com/c/189493
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Greg Daniel 2019-02-05 15:15:31 -05:00 committed by Skia Commit-Bot
parent 0ec8ec27b8
commit d742b6be45
3 changed files with 127 additions and 10 deletions

View File

@ -36,7 +36,7 @@ GrMtlBuffer::GrMtlBuffer(GrMtlGpu* gpu, size_t size, GrGpuBufferType intendedTyp
fIsDynamic = false;
// The managed resource mode is only available for macOS. iOS should use shared.
fMtlBuffer =
fMtlBuffer = size == 0 ? nil :
[gpu->device() newBufferWithLength: size
options: !fIsDynamic ? MTLResourceStorageModePrivate
#ifdef SK_BUILD_FOR_MAC

View File

@ -63,17 +63,11 @@ public:
}
GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
SkColorType) const override {
return kUnknown_GrPixelConfig;
}
SkColorType) const override;
GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, SkColorType) const override {
return kUnknown_GrPixelConfig;
}
GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, SkColorType) const override;
GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override {
return kUnknown_GrPixelConfig;
}
GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
GrSRGBEncoded srgbEncoded) const override;

View File

@ -423,6 +423,129 @@ void GrMtlCaps::initStencilFormat(id<MTLDevice> physDev) {
fPreferredStencilFormat = StencilFormat{ MTLPixelFormatStencil8, 8, 8, true };
}
GrPixelConfig validate_sized_format(GrMTLPixelFormat grFormat, SkColorType ct) {
MTLPixelFormat format = static_cast<MTLPixelFormat>(grFormat);
switch (ct) {
case kUnknown_SkColorType:
return kUnknown_GrPixelConfig;
case kAlpha_8_SkColorType:
if (MTLPixelFormatA8Unorm == format) {
return kAlpha_8_as_Alpha_GrPixelConfig;
} else if (MTLPixelFormatR8Unorm == format) {
return kAlpha_8_as_Red_GrPixelConfig;
}
break;
#ifdef SK_BUILD_FOR_MAC
case kRGB_565_SkColorType:
case kARGB_4444_SkColorType:
return kUnknown_GrPixelConfig;
break;
#else
case kRGB_565_SkColorType:
if (MTLPixelFormatB5G6R5Unorm == format) {
return kRGB_565_GrPixelConfig;
}
break;
case kARGB_4444_SkColorType:
if (MTLPixelFormatABGR4Unorm == format) {
return kRGBA_4444_GrPixelConfig;
}
break;
#endif
case kRGBA_8888_SkColorType:
if (MTLPixelFormatRGBA8Unorm == format) {
return kRGBA_8888_GrPixelConfig;
} else if (MTLPixelFormatRGBA8Unorm_sRGB == format) {
return kSRGBA_8888_GrPixelConfig;
}
break;
case kRGB_888x_SkColorType:
break;
case kBGRA_8888_SkColorType:
if (MTLPixelFormatBGRA8Unorm == format) {
return kBGRA_8888_GrPixelConfig;
} else if (MTLPixelFormatBGRA8Unorm_sRGB == format) {
return kSBGRA_8888_GrPixelConfig;
}
break;
case kRGBA_1010102_SkColorType:
if (MTLPixelFormatRGB10A2Unorm == format) {
return kRGBA_1010102_GrPixelConfig;
}
break;
case kRGB_101010x_SkColorType:
break;
case kGray_8_SkColorType:
if (MTLPixelFormatR8Unorm == format) {
return kGray_8_as_Red_GrPixelConfig;
}
break;
case kRGBA_F16_SkColorType:
if (MTLPixelFormatRG16Float == format) {
return kRGBA_half_GrPixelConfig;
}
break;
case kRGBA_F32_SkColorType:
if (MTLPixelFormatR32Float == format) {
return kRGBA_float_GrPixelConfig;
}
break;
}
return kUnknown_GrPixelConfig;
}
GrPixelConfig GrMtlCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt,
SkColorType ct) const {
GrMtlTextureInfo fbInfo;
if (!rt.getMtlTextureInfo(&fbInfo)) {
return kUnknown_GrPixelConfig;
}
id<MTLTexture> texture = (__bridge id<MTLTexture>)fbInfo.fTexture;
return validate_sized_format(texture.pixelFormat, ct);
}
GrPixelConfig GrMtlCaps::getConfigFromBackendFormat(const GrBackendFormat& format,
SkColorType ct) const {
const GrMTLPixelFormat* mtlFormat = format.getMtlFormat();
if (!mtlFormat) {
return kUnknown_GrPixelConfig;
}
return validate_sized_format(*mtlFormat, ct);
}
static GrPixelConfig get_yuva_config(GrMTLPixelFormat grFormat) {
MTLPixelFormat format = static_cast<MTLPixelFormat>(grFormat);
switch (format) {
case MTLPixelFormatA8Unorm:
return kAlpha_8_as_Alpha_GrPixelConfig;
break;
case MTLPixelFormatR8Unorm:
return kAlpha_8_as_Red_GrPixelConfig;
break;
// TODO: Add RG_88 format here
case MTLPixelFormatRGBA8Unorm:
return kRGBA_8888_GrPixelConfig;
break;
case MTLPixelFormatBGRA8Unorm:
return kBGRA_8888_GrPixelConfig;
break;
default:
return kUnknown_GrPixelConfig;
break;
}
}
GrPixelConfig GrMtlCaps::getYUVAConfigFromBackendFormat(const GrBackendFormat& format) const {
const GrMTLPixelFormat* mtlFormat = format.getMtlFormat();
if (!mtlFormat) {
return kUnknown_GrPixelConfig;
}
return get_yuva_config(*mtlFormat);
}
GrBackendFormat GrMtlCaps::getBackendFormatFromGrColorType(GrColorType ct,
GrSRGBEncoded srgbEncoded) const {
GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded);