mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-09 03:29:43 -10:00
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.
This commit is contained in:
1 parent
f88e39ab99
commit
667256a797
1 file changed
+53
-3
@@ -28,7 +28,29 @@
|
||||
|
||||
#ifdef OSX
|
||||
#import <AppKit/AppKit.h>
|
||||
/* <CoreGraphics/CoreGraphics.h> is a 10.8+ umbrella header.
|
||||
* On earlier SDKs (including the 10.5 Leopard SDK used by Xcode 3.1
|
||||
* on PowerPC), the same types are reachable through the
|
||||
* ApplicationServices umbrella. */
|
||||
#include <AvailabilityMacros.h>
|
||||
#if defined(MAC_OS_X_VERSION_10_8) && \
|
||||
(!defined(MAC_OS_X_VERSION_MIN_REQUIRED) || \
|
||||
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8)
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#else
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
#endif
|
||||
/* The CGDisplayModeRef family (CGDisplayCopyAllDisplayModes,
|
||||
* CGDisplayModeGetWidth, CGDisplaySetDisplayMode, ...) arrived in
|
||||
* 10.6 Snow Leopard. The 10.5 SDK only offers the older
|
||||
* CGDisplayAvailableModes / CFDictionaryRef path, which is a
|
||||
* different enough API that we just stub the resolution list on
|
||||
* pre-10.6 targets rather than port to both. */
|
||||
#if defined(MAC_OS_X_VERSION_10_6) && \
|
||||
(!defined(MAC_OS_X_VERSION_MIN_REQUIRED) || \
|
||||
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
|
||||
#define RARCH_HAS_CGDISPLAYMODE_API 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef OSX
|
||||
@@ -222,6 +244,7 @@ static void *apple_display_server_get_resolution_list(
|
||||
double currentRate;
|
||||
|
||||
#ifdef OSX
|
||||
#ifdef RARCH_HAS_CGDISPLAYMODE_API
|
||||
CGDirectDisplayID mainDisplayID = CGMainDisplayID();
|
||||
CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(mainDisplayID);
|
||||
currentRate = CGDisplayModeGetRefreshRate(currentMode);
|
||||
@@ -316,6 +339,33 @@ static void *apple_display_server_get_resolution_list(
|
||||
CFRelease(currentMode);
|
||||
RARCH_LOG("Found %u display modes on macOS\n", *len);
|
||||
return conf;
|
||||
#else
|
||||
/* pre-10.6 Leopard/Tiger fallback: CGDisplayModeRef doesn't exist
|
||||
* here and the older CGDisplayAvailableModes API is a different
|
||||
* shape. Just report the current resolution as a single entry
|
||||
* and skip mode enumeration; resolution-switching isn't supported
|
||||
* on these targets anyway. */
|
||||
CGDirectDisplayID mainDisplayID = CGMainDisplayID();
|
||||
size_t currentWidth = CGDisplayPixelsWide(mainDisplayID);
|
||||
size_t currentHeight = CGDisplayPixelsHigh(mainDisplayID);
|
||||
|
||||
*len = 1;
|
||||
if (!(conf = (struct video_display_config*)calloc(1, sizeof(*conf))))
|
||||
return NULL;
|
||||
conf[0].width = (unsigned)currentWidth;
|
||||
conf[0].height = (unsigned)currentHeight;
|
||||
conf[0].bpp = 32;
|
||||
conf[0].refreshrate = 60;
|
||||
conf[0].refreshrate_float = 60.0f;
|
||||
conf[0].interlaced = false;
|
||||
conf[0].dblscan = false;
|
||||
conf[0].idx = 0;
|
||||
conf[0].current = true;
|
||||
(void)currentRate;
|
||||
RARCH_LOG("[Video] Legacy macOS: reporting current mode %ux%u only\n",
|
||||
conf[0].width, conf[0].height);
|
||||
return conf;
|
||||
#endif /* RARCH_HAS_CGDISPLAYMODE_API */
|
||||
#else
|
||||
/* iOS/tvOS: Only enumerate refresh rates for current resolution */
|
||||
unsigned width, height;
|
||||
@@ -438,7 +488,7 @@ static enum rotation apple_display_server_get_screen_orientation(void *data)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#ifdef OSX
|
||||
#if defined(OSX) && defined(RARCH_HAS_CGDISPLAYMODE_API)
|
||||
CGDisplayModeRef original_mode;
|
||||
CGDirectDisplayID display_id;
|
||||
#endif
|
||||
@@ -450,7 +500,7 @@ static void *apple_display_server_init(void)
|
||||
if (!apple)
|
||||
return NULL;
|
||||
|
||||
#ifdef OSX
|
||||
#if defined(OSX) && defined(RARCH_HAS_CGDISPLAYMODE_API)
|
||||
/* Store original display mode for restoration */
|
||||
apple->display_id = CGMainDisplayID();
|
||||
apple->original_mode = CGDisplayCopyDisplayMode(apple->display_id);
|
||||
@@ -503,7 +553,7 @@ static void apple_display_server_destroy(void *data)
|
||||
if (!apple)
|
||||
return;
|
||||
|
||||
#ifdef OSX
|
||||
#if defined(OSX) && defined(RARCH_HAS_CGDISPLAYMODE_API)
|
||||
/* Restore original display mode */
|
||||
if (apple->original_mode)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user