mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-23 20:25:33 +00:00
macOS: Expose more display modes on retina screens. Fixes an issue found in BZFlag.
This commit is contained in:
parent
49f846f113
commit
8292d73ebb
|
@ -100,15 +100,47 @@ CG_SetError(const char *prefix, CGDisplayErr result)
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool
|
||||||
GetDisplayMode(_THIS, CGDisplayModeRef vidmode, CVDisplayLinkRef link, SDL_DisplayMode *mode)
|
GetDisplayMode(_THIS, CGDisplayModeRef vidmode, CFArrayRef modelist, CVDisplayLinkRef link, SDL_DisplayMode *mode)
|
||||||
{
|
{
|
||||||
SDL_DisplayModeData *data;
|
SDL_DisplayModeData *data;
|
||||||
int width = 0;
|
int width = (int) CGDisplayModeGetWidth(vidmode);
|
||||||
int height = 0;
|
int height = (int) CGDisplayModeGetHeight(vidmode);
|
||||||
int bpp = 0;
|
int bpp = 0;
|
||||||
int refreshRate = 0;
|
int refreshRate = 0;
|
||||||
CFStringRef fmt;
|
CFStringRef fmt;
|
||||||
|
|
||||||
|
/* Ignore this mode if it's low-dpi (@1x) and we have a high-dpi mode in the
|
||||||
|
* list with the same size in points.
|
||||||
|
*/
|
||||||
|
#ifdef MAC_OS_X_VERSION_10_8
|
||||||
|
if (modelist != NULL && floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_7) {
|
||||||
|
int pixelW = (int) CGDisplayModeGetPixelWidth(vidmode);
|
||||||
|
int pixelH = (int) CGDisplayModeGetPixelHeight(vidmode);
|
||||||
|
|
||||||
|
if (width == pixelW && height == pixelH) {
|
||||||
|
CFIndex modescount = CFArrayGetCount(modelist);
|
||||||
|
|
||||||
|
for (int i = 0; i < modescount; i++) {
|
||||||
|
CGDisplayModeRef othermode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modelist, i);
|
||||||
|
|
||||||
|
if (CFEqual(vidmode, othermode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int otherW = (int) CGDisplayModeGetWidth(othermode);
|
||||||
|
int otherH = (int) CGDisplayModeGetHeight(othermode);
|
||||||
|
|
||||||
|
int otherpixelW = (int) CGDisplayModeGetPixelWidth(othermode);
|
||||||
|
int otherpixelH = (int) CGDisplayModeGetPixelHeight(othermode);
|
||||||
|
|
||||||
|
if (width == otherW && height == otherH && (otherpixelW != otherW || otherpixelH != otherH)) {
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
|
data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
|
@ -116,8 +148,6 @@ GetDisplayMode(_THIS, CGDisplayModeRef vidmode, CVDisplayLinkRef link, SDL_Displ
|
||||||
data->moderef = vidmode;
|
data->moderef = vidmode;
|
||||||
|
|
||||||
fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
fmt = CGDisplayModeCopyPixelEncoding(vidmode);
|
||||||
width = (int) CGDisplayModeGetWidth(vidmode);
|
|
||||||
height = (int) CGDisplayModeGetHeight(vidmode);
|
|
||||||
refreshRate = (int) (CGDisplayModeGetRefreshRate(vidmode) + 0.5);
|
refreshRate = (int) (CGDisplayModeGetRefreshRate(vidmode) + 0.5);
|
||||||
|
|
||||||
if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
|
if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
|
||||||
|
@ -243,7 +273,7 @@ Cocoa_InitModes(_THIS)
|
||||||
SDL_zero(display);
|
SDL_zero(display);
|
||||||
/* this returns a stddup'ed string */
|
/* this returns a stddup'ed string */
|
||||||
display.name = (char *)Cocoa_GetDisplayName(displays[i]);
|
display.name = (char *)Cocoa_GetDisplayName(displays[i]);
|
||||||
if (!GetDisplayMode(_this, moderef, link, &mode)) {
|
if (!GetDisplayMode(_this, moderef, NULL, link, &mode)) {
|
||||||
CVDisplayLinkRelease(link);
|
CVDisplayLinkRelease(link);
|
||||||
CGDisplayModeRelease(moderef);
|
CGDisplayModeRelease(moderef);
|
||||||
SDL_free(display.name);
|
SDL_free(display.name);
|
||||||
|
@ -340,7 +370,29 @@ void
|
||||||
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||||
{
|
{
|
||||||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||||
CFArrayRef modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
|
CFDictionaryRef dict = NULL;
|
||||||
|
CFArrayRef modes;
|
||||||
|
|
||||||
|
/* By default, CGDisplayCopyAllDisplayModes will only get a subset of the
|
||||||
|
* system's available modes. For example on a 15" 2016 MBP, users can
|
||||||
|
* choose 1920x1080@2x in System Preferences but it won't show up here,
|
||||||
|
* unless we specify the option below.
|
||||||
|
*/
|
||||||
|
#ifdef MAC_OS_X_VERSION_10_8
|
||||||
|
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_7) {
|
||||||
|
const CFStringRef dictkeys[] = {kCGDisplayShowDuplicateLowResolutionModes};
|
||||||
|
const CFBooleanRef dictvalues[] = {kCFBooleanTrue};
|
||||||
|
dict = CFDictionaryCreate(NULL,
|
||||||
|
(const void **)dictkeys,
|
||||||
|
(const void **)dictvalues,
|
||||||
|
1,
|
||||||
|
&kCFCopyStringDictionaryKeyCallBacks,
|
||||||
|
&kCFTypeDictionaryValueCallBacks);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
modes = CGDisplayCopyAllDisplayModes(data->display, dict);
|
||||||
|
CFRelease(dict);
|
||||||
|
|
||||||
if (modes) {
|
if (modes) {
|
||||||
CVDisplayLinkRef link = NULL;
|
CVDisplayLinkRef link = NULL;
|
||||||
|
@ -352,7 +404,7 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
CGDisplayModeRef moderef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
|
CGDisplayModeRef moderef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
|
||||||
SDL_DisplayMode mode;
|
SDL_DisplayMode mode;
|
||||||
if (GetDisplayMode(_this, moderef, link, &mode)) {
|
if (GetDisplayMode(_this, moderef, modes, link, &mode)) {
|
||||||
CGDisplayModeRetain(moderef);
|
CGDisplayModeRetain(moderef);
|
||||||
SDL_AddDisplayMode(display, &mode);
|
SDL_AddDisplayMode(display, &mode);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue