mirror of
https://github.com/love2d/megasource.git
synced 2026-08-20 20:50:52 +02:00
update SDL3 to latest commit
This commit is contained in:
@@ -24,14 +24,14 @@
|
||||
|
||||
#include "SDL_cocoavideo.h"
|
||||
|
||||
/* We need this for IODisplayCreateInfoDictionary and kIODisplayOnlyPreferredName */
|
||||
// We need this for IODisplayCreateInfoDictionary and kIODisplayOnlyPreferredName
|
||||
#include <IOKit/graphics/IOGraphicsLib.h>
|
||||
|
||||
/* We need this for CVDisplayLinkGetNominalOutputVideoRefreshPeriod */
|
||||
// We need this for CVDisplayLinkGetNominalOutputVideoRefreshPeriod
|
||||
#include <CoreVideo/CVBase.h>
|
||||
#include <CoreVideo/CVDisplayLink.h>
|
||||
|
||||
/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
|
||||
// This gets us MAC_OS_X_VERSION_MIN_REQUIRED...
|
||||
#include <AvailabilityMacros.h>
|
||||
|
||||
#ifndef MAC_OS_X_VERSION_10_13
|
||||
@@ -41,7 +41,7 @@
|
||||
#define kDisplayModeNativeFlag 0x02000000
|
||||
#endif
|
||||
|
||||
static int CG_SetError(const char *prefix, CGDisplayErr result)
|
||||
static bool CG_SetError(const char *prefix, CGDisplayErr result)
|
||||
{
|
||||
const char *error;
|
||||
|
||||
@@ -87,7 +87,7 @@ static NSScreen *GetNSScreenForDisplayID(CGDirectDisplayID displayID)
|
||||
{
|
||||
NSArray *screens = [NSScreen screens];
|
||||
|
||||
/* !!! FIXME: maybe track the NSScreen in SDL_DisplayData? */
|
||||
// !!! FIXME: maybe track the NSScreen in SDL_DisplayData?
|
||||
for (NSScreen *screen in screens) {
|
||||
const CGDirectDisplayID thisDisplay = (CGDirectDisplayID)[[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
|
||||
if (thisDisplay == displayID) {
|
||||
@@ -99,39 +99,39 @@ static NSScreen *GetNSScreenForDisplayID(CGDirectDisplayID displayID)
|
||||
|
||||
static float GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef link)
|
||||
{
|
||||
double refreshRate = CGDisplayModeGetRefreshRate(vidmode);
|
||||
float refreshRate = (float)CGDisplayModeGetRefreshRate(vidmode);
|
||||
|
||||
/* CGDisplayModeGetRefreshRate can return 0 (eg for built-in displays). */
|
||||
// CGDisplayModeGetRefreshRate can return 0 (eg for built-in displays).
|
||||
if (refreshRate == 0 && link != NULL) {
|
||||
CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
|
||||
if ((time.flags & kCVTimeIsIndefinite) == 0 && time.timeValue != 0) {
|
||||
refreshRate = (double)time.timeScale / time.timeValue;
|
||||
refreshRate = (float)time.timeScale / time.timeValue;
|
||||
}
|
||||
}
|
||||
|
||||
return (int)(refreshRate * 100) / 100.0f;
|
||||
return refreshRate;
|
||||
}
|
||||
|
||||
static SDL_bool HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
|
||||
static bool HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
|
||||
{
|
||||
uint32_t ioflags = CGDisplayModeGetIOFlags(vidmode);
|
||||
|
||||
/* Filter out modes which have flags that we don't want. */
|
||||
// Filter out modes which have flags that we don't want.
|
||||
if (ioflags & (kDisplayModeNeverShowFlag | kDisplayModeNotGraphicsQualityFlag)) {
|
||||
return SDL_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Filter out modes which don't have flags that we want. */
|
||||
// Filter out modes which don't have flags that we want.
|
||||
if (!(ioflags & kDisplayModeValidFlag) || !(ioflags & kDisplayModeSafeFlag)) {
|
||||
return SDL_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
static Uint32 GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
|
||||
{
|
||||
/* This API is deprecated in 10.11 with no good replacement (as of 10.15). */
|
||||
// This API is deprecated in 10.11 with no good replacement (as of 10.15).
|
||||
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
||||
Uint32 pixelformat = SDL_PIXELFORMAT_UNKNOWN;
|
||||
|
||||
@@ -145,7 +145,7 @@ static Uint32 GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
|
||||
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||
pixelformat = SDL_PIXELFORMAT_ARGB2101010;
|
||||
} else {
|
||||
/* ignore 8-bit and such for now. */
|
||||
// ignore 8-bit and such for now.
|
||||
}
|
||||
|
||||
CFRelease(fmt);
|
||||
@@ -153,7 +153,7 @@ static Uint32 GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
|
||||
return pixelformat;
|
||||
}
|
||||
|
||||
static SDL_bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArrayRef modelist, CVDisplayLinkRef link, SDL_DisplayMode *mode)
|
||||
static bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode, bool vidmodeCurrent, CFArrayRef modelist, CVDisplayLinkRef link, SDL_DisplayMode *mode)
|
||||
{
|
||||
SDL_DisplayModeData *data;
|
||||
bool usableForGUI = CGDisplayModeIsUsableForDesktopGUI(vidmode);
|
||||
@@ -168,13 +168,13 @@ static SDL_bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode,
|
||||
CFMutableArrayRef modes;
|
||||
|
||||
if (format == SDL_PIXELFORMAT_UNKNOWN) {
|
||||
return SDL_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Don't fail the current mode based on flags because this could prevent Cocoa_InitModes from
|
||||
* succeeding if the current mode lacks certain flags (esp kDisplayModeSafeFlag). */
|
||||
if (!vidmodeCurrent && !HasValidDisplayModeFlags(vidmode)) {
|
||||
return SDL_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
modes = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
|
||||
@@ -221,7 +221,7 @@ static SDL_bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode,
|
||||
*/
|
||||
if (interlaced && ((otherioflags & kDisplayModeInterlacedFlag) == 0) && width == otherW && height == otherH && pixelW == otherpixelW && pixelH == otherpixelH && refreshrate == otherrefresh && format == otherformat && usableForGUI == otherGUI) {
|
||||
CFRelease(modes);
|
||||
return SDL_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Ignore this mode if it's not usable for desktop UI and its
|
||||
@@ -229,7 +229,7 @@ static SDL_bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode,
|
||||
*/
|
||||
if (width == otherW && height == otherH && pixelW == otherpixelW && pixelH == otherpixelH && !usableForGUI && otherGUI && refreshrate == otherrefresh && format == otherformat) {
|
||||
CFRelease(modes);
|
||||
return SDL_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If multiple modes have the exact same properties, they'll all
|
||||
@@ -263,7 +263,7 @@ static SDL_bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode,
|
||||
data = (SDL_DisplayModeData *)SDL_malloc(sizeof(*data));
|
||||
if (!data) {
|
||||
CFRelease(modes);
|
||||
return SDL_FALSE;
|
||||
return false;
|
||||
}
|
||||
data->modes = modes;
|
||||
mode->format = format;
|
||||
@@ -271,13 +271,13 @@ static SDL_bool GetDisplayMode(SDL_VideoDevice *_this, CGDisplayModeRef vidmode,
|
||||
mode->h = (int)height;
|
||||
mode->pixel_density = (float)pixelW / width;
|
||||
mode->refresh_rate = refreshrate;
|
||||
mode->driverdata = data;
|
||||
return SDL_TRUE;
|
||||
mode->internal = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
static char *Cocoa_GetDisplayName(CGDirectDisplayID displayID)
|
||||
{
|
||||
/* This API is deprecated in 10.9 with no good replacement (as of 10.15). */
|
||||
// This API is deprecated in 10.9 with no good replacement (as of 10.15).
|
||||
io_service_t servicePort = CGDisplayIOServicePort(displayID);
|
||||
CFDictionaryRef deviceInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
|
||||
NSDictionary *localizedNames = [(__bridge NSDictionary *)deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
|
||||
@@ -290,12 +290,12 @@ static char *Cocoa_GetDisplayName(CGDirectDisplayID displayID)
|
||||
return displayName;
|
||||
}
|
||||
|
||||
static void Cocoa_GetHDRProperties(CGDirectDisplayID displayID, SDL_HDRDisplayProperties *HDR)
|
||||
static void Cocoa_GetHDRProperties(CGDirectDisplayID displayID, SDL_HDROutputProperties *HDR)
|
||||
{
|
||||
HDR->SDR_white_point = 1.0f;
|
||||
HDR->SDR_white_level = 1.0f;
|
||||
HDR->HDR_headroom = 1.0f;
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 /* Added in the 10.15 SDK */
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 // Added in the 10.15 SDK
|
||||
if (@available(macOS 10.15, *)) {
|
||||
NSScreen *screen = GetNSScreenForDisplayID(displayID);
|
||||
if (screen) {
|
||||
@@ -315,7 +315,7 @@ void Cocoa_InitModes(SDL_VideoDevice *_this)
|
||||
CGDisplayErr result;
|
||||
CGDirectDisplayID *displays;
|
||||
CGDisplayCount numDisplays;
|
||||
SDL_bool isstack;
|
||||
bool isstack;
|
||||
int pass, i;
|
||||
|
||||
result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
|
||||
@@ -331,7 +331,7 @@ void Cocoa_InitModes(SDL_VideoDevice *_this)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Pick up the primary display in the first pass, then get the rest */
|
||||
// Pick up the primary display in the first pass, then get the rest
|
||||
for (pass = 0; pass < 2; ++pass) {
|
||||
for (i = 0; i < numDisplays; ++i) {
|
||||
SDL_VideoDisplay display;
|
||||
@@ -370,9 +370,9 @@ void Cocoa_InitModes(SDL_VideoDevice *_this)
|
||||
CVDisplayLinkCreateWithCGDisplay(displays[i], &link);
|
||||
|
||||
SDL_zero(display);
|
||||
/* this returns a strdup'ed string */
|
||||
// this returns a strdup'ed string
|
||||
display.name = Cocoa_GetDisplayName(displays[i]);
|
||||
if (!GetDisplayMode(_this, moderef, SDL_TRUE, NULL, link, &mode)) {
|
||||
if (!GetDisplayMode(_this, moderef, true, NULL, link, &mode)) {
|
||||
CVDisplayLinkRelease(link);
|
||||
CGDisplayModeRelease(moderef);
|
||||
SDL_free(display.name);
|
||||
@@ -386,8 +386,8 @@ void Cocoa_InitModes(SDL_VideoDevice *_this)
|
||||
Cocoa_GetHDRProperties(displaydata->display, &display.HDR);
|
||||
|
||||
display.desktop_mode = mode;
|
||||
display.driverdata = displaydata;
|
||||
SDL_AddVideoDisplay(&display, SDL_FALSE);
|
||||
display.internal = displaydata;
|
||||
SDL_AddVideoDisplay(&display, false);
|
||||
SDL_free(display.name);
|
||||
}
|
||||
}
|
||||
@@ -397,21 +397,21 @@ void Cocoa_InitModes(SDL_VideoDevice *_this)
|
||||
|
||||
void Cocoa_UpdateDisplays(SDL_VideoDevice *_this)
|
||||
{
|
||||
SDL_HDRDisplayProperties HDR;
|
||||
SDL_HDROutputProperties HDR;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < _this->num_displays; ++i) {
|
||||
SDL_VideoDisplay *display = _this->displays[i];
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
|
||||
|
||||
Cocoa_GetHDRProperties(displaydata->display, &HDR);
|
||||
SDL_SetDisplayHDRProperties(display, &HDR);
|
||||
}
|
||||
}
|
||||
|
||||
int Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
bool Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
{
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
|
||||
CGRect cgrect;
|
||||
|
||||
cgrect = CGDisplayBounds(displaydata->display);
|
||||
@@ -419,12 +419,12 @@ int Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SD
|
||||
rect->y = (int)cgrect.origin.y;
|
||||
rect->w = (int)cgrect.size.width;
|
||||
rect->h = (int)cgrect.size.height;
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
bool Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
{
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
|
||||
NSScreen *screen = GetNSScreenForDisplayID(displaydata->display);
|
||||
|
||||
if (screen == nil) {
|
||||
@@ -439,12 +439,12 @@ int Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ
|
||||
rect->h = (int)frame.size.height;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
||||
bool Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
||||
{
|
||||
SDL_DisplayData *data = (SDL_DisplayData *)display->driverdata;
|
||||
SDL_DisplayData *data = (SDL_DisplayData *)display->internal;
|
||||
CVDisplayLinkRef link = NULL;
|
||||
CFArrayRef modes;
|
||||
CFDictionaryRef dict = NULL;
|
||||
@@ -486,10 +486,10 @@ int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
||||
CGDisplayModeRef moderef = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
|
||||
SDL_DisplayMode mode;
|
||||
|
||||
if (GetDisplayMode(_this, moderef, SDL_FALSE, modes, link, &mode)) {
|
||||
if (GetDisplayMode(_this, moderef, false, modes, link, &mode)) {
|
||||
if (!SDL_AddFullscreenDisplayMode(display, &mode)) {
|
||||
CFRelease(((SDL_DisplayModeData *)mode.driverdata)->modes);
|
||||
SDL_free(mode.driverdata);
|
||||
CFRelease(mode.internal->modes);
|
||||
SDL_free(mode.internal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,7 +498,7 @@ int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
||||
}
|
||||
|
||||
CVDisplayLinkRelease(link);
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayModeData *data)
|
||||
@@ -511,7 +511,7 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo
|
||||
CGDisplayModeRef moderef = (CGDisplayModeRef)CFArrayGetValueAtIndex(data->modes, i);
|
||||
result = CGDisplaySetDisplayMode(display, moderef, NULL);
|
||||
if (result == kCGErrorSuccess) {
|
||||
/* If this mode works, try it first next time. */
|
||||
// If this mode works, try it first next time.
|
||||
CFArrayExchangeValuesAtIndices(data->modes, i, 0);
|
||||
break;
|
||||
}
|
||||
@@ -519,41 +519,40 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo
|
||||
return result;
|
||||
}
|
||||
|
||||
int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
|
||||
bool Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
|
||||
{
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||
SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
|
||||
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
|
||||
SDL_DisplayModeData *data = mode->internal;
|
||||
CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
|
||||
CGError result = kCGErrorSuccess;
|
||||
|
||||
b_inModeTransition = SDL_TRUE;
|
||||
b_inModeTransition = true;
|
||||
|
||||
/* Fade to black to hide resolution-switching flicker */
|
||||
// Fade to black to hide resolution-switching flicker
|
||||
if (CGAcquireDisplayFadeReservation(5, &fade_token) == kCGErrorSuccess) {
|
||||
CGDisplayFade(fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
|
||||
}
|
||||
|
||||
if (data == display->desktop_mode.driverdata) {
|
||||
/* Restoring desktop mode */
|
||||
if (data == display->desktop_mode.internal) {
|
||||
// Restoring desktop mode
|
||||
SetDisplayModeForDisplay(displaydata->display, data);
|
||||
} else {
|
||||
/* Do the physical switch */
|
||||
// Do the physical switch
|
||||
result = SetDisplayModeForDisplay(displaydata->display, data);
|
||||
}
|
||||
|
||||
/* Fade in again (asynchronously) */
|
||||
// Fade in again (asynchronously)
|
||||
if (fade_token != kCGDisplayFadeReservationInvalidToken) {
|
||||
CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
|
||||
CGReleaseDisplayFadeReservation(fade_token);
|
||||
}
|
||||
|
||||
b_inModeTransition = SDL_FALSE;
|
||||
b_inModeTransition = false;
|
||||
|
||||
if (result != kCGErrorSuccess) {
|
||||
CG_SetError("CGDisplaySwitchToMode()", result);
|
||||
return -1;
|
||||
return CG_SetError("CGDisplaySwitchToMode()", result);
|
||||
}
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Cocoa_QuitModes(SDL_VideoDevice *_this)
|
||||
@@ -564,18 +563,18 @@ void Cocoa_QuitModes(SDL_VideoDevice *_this)
|
||||
SDL_VideoDisplay *display = _this->displays[i];
|
||||
SDL_DisplayModeData *mode;
|
||||
|
||||
if (display->current_mode->driverdata != display->desktop_mode.driverdata) {
|
||||
if (display->current_mode->internal != display->desktop_mode.internal) {
|
||||
Cocoa_SetDisplayMode(_this, display, &display->desktop_mode);
|
||||
}
|
||||
|
||||
mode = (SDL_DisplayModeData *)display->desktop_mode.driverdata;
|
||||
mode = display->desktop_mode.internal;
|
||||
CFRelease(mode->modes);
|
||||
|
||||
for (j = 0; j < display->num_fullscreen_modes; j++) {
|
||||
mode = (SDL_DisplayModeData *)display->fullscreen_modes[j].driverdata;
|
||||
mode = display->fullscreen_modes[j].internal;
|
||||
CFRelease(mode->modes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
#endif // SDL_VIDEO_DRIVER_COCOA
|
||||
|
||||
Reference in New Issue
Block a user