mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-29 20:27:12 +01:00
cocoa: SDL_GetDisplayDPI() should account for Retina displays.
Fixes Bugzilla #4856.
This commit is contained in:
parent
b7576025e3
commit
ca2c8609e1
@ -443,27 +443,41 @@ Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
|
|||||||
|
|
||||||
int
|
int
|
||||||
Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
|
Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
|
||||||
|
{ @autoreleasepool
|
||||||
{
|
{
|
||||||
const float MM_IN_INCH = 25.4f;
|
const float MM_IN_INCH = 25.4f;
|
||||||
|
|
||||||
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
|
||||||
|
|
||||||
CGSize displaySize = CGDisplayScreenSize(data->display);
|
/* we need the backingScaleFactor for Retina displays, which is only exposed through NSScreen, not CGDisplay, afaik, so find our screen... */
|
||||||
int pixelWidth = (int) CGDisplayPixelsWide(data->display);
|
CGFloat scaleFactor = 1.0f;
|
||||||
int pixelHeight = (int) CGDisplayPixelsHigh(data->display);
|
NSArray<NSScreen *> *screens = [NSScreen screens];
|
||||||
|
for (NSScreen *screen in screens) {
|
||||||
|
const CGDirectDisplayID dpyid = (const CGDirectDisplayID ) [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
|
||||||
|
if (dpyid == data->display) {
|
||||||
|
if ([screen respondsToSelector:@selector(backingScaleFactor)]) { // Mac OS X 10.7 and later
|
||||||
|
scaleFactor = [screen backingScaleFactor];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const CGSize displaySize = CGDisplayScreenSize(data->display);
|
||||||
|
const int pixelWidth = (int) CGDisplayPixelsWide(data->display);
|
||||||
|
const int pixelHeight = (int) CGDisplayPixelsHigh(data->display);
|
||||||
|
|
||||||
if (ddpi) {
|
if (ddpi) {
|
||||||
*ddpi = SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH);
|
*ddpi = (SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH)) * scaleFactor;
|
||||||
}
|
}
|
||||||
if (hdpi) {
|
if (hdpi) {
|
||||||
*hdpi = pixelWidth * MM_IN_INCH / displaySize.width;
|
*hdpi = (pixelWidth * MM_IN_INCH / displaySize.width) * scaleFactor;
|
||||||
}
|
}
|
||||||
if (vdpi) {
|
if (vdpi) {
|
||||||
*vdpi = pixelHeight * MM_IN_INCH / displaySize.height;
|
*vdpi = (pixelHeight * MM_IN_INCH / displaySize.height) * scaleFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}}
|
||||||
|
|
||||||
void
|
void
|
||||||
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
|
||||||
|
Loading…
Reference in New Issue
Block a user