Skip to content

Commit 667256a

Browse files
committed
dispserv_apple: gate CoreGraphics umbrella and CGDisplayMode APIs
gfx/display_servers/dispserv_apple.m hits two separate SDK cliffs on pre-10.8 macOS builds: dispserv_apple.m:31:38: error: CoreGraphics/CoreGraphics.h: No such file or directory The <CoreGraphics/CoreGraphics.h> umbrella header is 10.8+. Before that, the framework is reached through <ApplicationServices/ ApplicationServices.h>. Swap based on MAC_OS_X_VERSION_MIN_REQUIRED. The second, latent issue: CGDisplayModeRef and its accessors (CGDisplayCopyAllDisplayModes, CGDisplayModeGetWidth/Height, CGDisplaySetDisplayMode) all arrived in 10.6 Snow Leopard. The 10.5 SDK only exposes the older CGDisplayAvailableModes / CFDictionaryRef path, which is a different enough shape that porting to both isn't worth it for a driver whose job is mostly resolution switching. Introduce RARCH_HAS_CGDISPLAYMODE_API (defined on 10.6+ SDKs) and gate: - get_resolution_list OSX branch (modern path kept; fallback reports the current mode as a single entry using the pre-10.0 CGDisplayPixelsWide/High APIs) - apple_display_server_t.original_mode / display_id fields - init block that saves the original display mode - destroy block that restores it apple_display_server_set_resolution needs no change — it was already gated on __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000 (macOS 14 Sonoma). Pre-10.6 targets lose resolution-switching but keep window opacity/progress/decorations. Modern macOS builds see no change.
1 parent f88e39a commit 667256a

1 file changed

Lines changed: 53 additions & 3 deletions

File tree

gfx/display_servers/dispserv_apple.m

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,29 @@
2828

2929
#ifdef OSX
3030
#import <AppKit/AppKit.h>
31+
/* <CoreGraphics/CoreGraphics.h> is a 10.8+ umbrella header.
32+
* On earlier SDKs (including the 10.5 Leopard SDK used by Xcode 3.1
33+
* on PowerPC), the same types are reachable through the
34+
* ApplicationServices umbrella. */
35+
#include <AvailabilityMacros.h>
36+
#if defined(MAC_OS_X_VERSION_10_8) && \
37+
(!defined(MAC_OS_X_VERSION_MIN_REQUIRED) || \
38+
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8)
3139
#import <CoreGraphics/CoreGraphics.h>
40+
#else
41+
#import <ApplicationServices/ApplicationServices.h>
42+
#endif
43+
/* The CGDisplayModeRef family (CGDisplayCopyAllDisplayModes,
44+
* CGDisplayModeGetWidth, CGDisplaySetDisplayMode, ...) arrived in
45+
* 10.6 Snow Leopard. The 10.5 SDK only offers the older
46+
* CGDisplayAvailableModes / CFDictionaryRef path, which is a
47+
* different enough API that we just stub the resolution list on
48+
* pre-10.6 targets rather than port to both. */
49+
#if defined(MAC_OS_X_VERSION_10_6) && \
50+
(!defined(MAC_OS_X_VERSION_MIN_REQUIRED) || \
51+
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
52+
#define RARCH_HAS_CGDISPLAYMODE_API 1
53+
#endif
3254
#endif
3355

3456
#ifdef OSX
@@ -222,6 +244,7 @@ static bool apple_display_server_set_resolution(void *data,
222244
double currentRate;
223245

224246
#ifdef OSX
247+
#ifdef RARCH_HAS_CGDISPLAYMODE_API
225248
CGDirectDisplayID mainDisplayID = CGMainDisplayID();
226249
CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(mainDisplayID);
227250
currentRate = CGDisplayModeGetRefreshRate(currentMode);
@@ -316,6 +339,33 @@ static bool apple_display_server_set_resolution(void *data,
316339
CFRelease(currentMode);
317340
RARCH_LOG("Found %u display modes on macOS\n", *len);
318341
return conf;
342+
#else
343+
/* pre-10.6 Leopard/Tiger fallback: CGDisplayModeRef doesn't exist
344+
* here and the older CGDisplayAvailableModes API is a different
345+
* shape. Just report the current resolution as a single entry
346+
* and skip mode enumeration; resolution-switching isn't supported
347+
* on these targets anyway. */
348+
CGDirectDisplayID mainDisplayID = CGMainDisplayID();
349+
size_t currentWidth = CGDisplayPixelsWide(mainDisplayID);
350+
size_t currentHeight = CGDisplayPixelsHigh(mainDisplayID);
351+
352+
*len = 1;
353+
if (!(conf = (struct video_display_config*)calloc(1, sizeof(*conf))))
354+
return NULL;
355+
conf[0].width = (unsigned)currentWidth;
356+
conf[0].height = (unsigned)currentHeight;
357+
conf[0].bpp = 32;
358+
conf[0].refreshrate = 60;
359+
conf[0].refreshrate_float = 60.0f;
360+
conf[0].interlaced = false;
361+
conf[0].dblscan = false;
362+
conf[0].idx = 0;
363+
conf[0].current = true;
364+
(void)currentRate;
365+
RARCH_LOG("[Video] Legacy macOS: reporting current mode %ux%u only\n",
366+
conf[0].width, conf[0].height);
367+
return conf;
368+
#endif /* RARCH_HAS_CGDISPLAYMODE_API */
319369
#else
320370
/* iOS/tvOS: Only enumerate refresh rates for current resolution */
321371
unsigned width, height;
@@ -438,7 +488,7 @@ static enum rotation apple_display_server_get_screen_orientation(void *data)
438488

439489
typedef struct
440490
{
441-
#ifdef OSX
491+
#if defined(OSX) && defined(RARCH_HAS_CGDISPLAYMODE_API)
442492
CGDisplayModeRef original_mode;
443493
CGDirectDisplayID display_id;
444494
#endif
@@ -450,7 +500,7 @@ static enum rotation apple_display_server_get_screen_orientation(void *data)
450500
if (!apple)
451501
return NULL;
452502

453-
#ifdef OSX
503+
#if defined(OSX) && defined(RARCH_HAS_CGDISPLAYMODE_API)
454504
/* Store original display mode for restoration */
455505
apple->display_id = CGMainDisplayID();
456506
apple->original_mode = CGDisplayCopyDisplayMode(apple->display_id);
@@ -503,7 +553,7 @@ static void apple_display_server_destroy(void *data)
503553
if (!apple)
504554
return;
505555

506-
#ifdef OSX
556+
#if defined(OSX) && defined(RARCH_HAS_CGDISPLAYMODE_API)
507557
/* Restore original display mode */
508558
if (apple->original_mode)
509559
{

0 commit comments

Comments
 (0)