From 72c1a73caceb08ca748071af6d96fbf32bef00d3 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 12 Jan 2019 00:33:43 +0900 Subject: [PATCH] graphicsdriver/metal: Avoid using @available syntax for old Xcode (#781) --- internal/graphicsdriver/metal/ca/ca.go | 5 +++- internal/graphicsdriver/metal/ca/ca.m | 36 ++++++++++++++++---------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/internal/graphicsdriver/metal/ca/ca.go b/internal/graphicsdriver/metal/ca/ca.go index 4aedd5653..30f44aae5 100644 --- a/internal/graphicsdriver/metal/ca/ca.go +++ b/internal/graphicsdriver/metal/ca/ca.go @@ -28,7 +28,10 @@ import ( "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl" ) -// #cgo CFLAGS: -mmacosx-version-min=10.11 +// Suppress the warnings about availability guard with -Wno-unguarded-availability-new. +// It is because old Xcode (8 or older?) does not accept @available syntax. + +// #cgo CFLAGS: -mmacosx-version-min=10.11 -Wno-unguarded-availability-new // #cgo LDFLAGS: -framework QuartzCore -framework Foundation -framework CoreGraphics // // #include "ca.h" diff --git a/internal/graphicsdriver/metal/ca/ca.m b/internal/graphicsdriver/metal/ca/ca.m index 4b04a06b4..b168c8d18 100644 --- a/internal/graphicsdriver/metal/ca/ca.m +++ b/internal/graphicsdriver/metal/ca/ca.m @@ -46,27 +46,35 @@ const char *MetalLayer_SetPixelFormat(void *metalLayer, uint16_t pixelFormat) { const char *MetalLayer_SetMaximumDrawableCount(void *metalLayer, uint_t maximumDrawableCount) { - if (@available(macOS 10.13.2, *)) { - @try { - if ([(CAMetalLayer *)metalLayer - respondsToSelector:@selector(setMaximumDrawableCount:)]) { - [((CAMetalLayer *)metalLayer) - setMaximumDrawableCount:(NSUInteger)maximumDrawableCount]; - } - } @catch (NSException *exception) { - return exception.reason.UTF8String; + // @available syntax is not available for old Xcode (#781) + // + // If possible, we'd want to write the guard like: + // + // if (@available(macOS 10.13.2, *)) { ... + + @try { + if ([(CAMetalLayer *)metalLayer + respondsToSelector:@selector(setMaximumDrawableCount:)]) { + [((CAMetalLayer *)metalLayer) + setMaximumDrawableCount:(NSUInteger)maximumDrawableCount]; } + } @catch (NSException *exception) { + return exception.reason.UTF8String; } return NULL; } void MetalLayer_SetDisplaySyncEnabled(void *metalLayer, BOOL displaySyncEnabled) { - if (@available(macOS 10.13, *)) { - if ([(CAMetalLayer *)metalLayer - respondsToSelector:@selector(setDisplaySyncEnabled:)]) { - [((CAMetalLayer *)metalLayer) setDisplaySyncEnabled:displaySyncEnabled]; - } + // @available syntax is not available for old Xcode (#781) + // + // If possible, we'd want to write the guard like: + // + // if (@available(macOS 10.13, *)) { ... + + if ([(CAMetalLayer *)metalLayer + respondsToSelector:@selector(setDisplaySyncEnabled:)]) { + [((CAMetalLayer *)metalLayer) setDisplaySyncEnabled:displaySyncEnabled]; } }