Removed SDL_GetDisplayDPI()

This function wasn't consistently correct across platforms and devices.

If you want the UI scale factor, you can use display_scale in the structure returned by SDL_GetDesktopDisplayMode(). If you need an approximate DPI, you can multiply this value times 160 on iPhone and Android, and 96 on other platforms.
This commit is contained in:
Sam Lantinga
2023-02-08 15:07:13 -08:00
parent b7c6fec10a
commit 824b9b0a58
28 changed files with 32 additions and 542 deletions

View File

@@ -30,7 +30,6 @@
- (instancetype)initWithScreen:(UIScreen *)screen;
@property(nonatomic, strong) UIScreen *uiscreen;
@property(nonatomic) float screenDPI;
@end
@@ -46,7 +45,6 @@ extern int UIKit_InitModes(_THIS);
extern int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event);
extern void UIKit_DelDisplay(UIScreen *uiscreen);
extern int UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
extern int UIKit_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
extern int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
extern void UIKit_QuitModes(_THIS);
extern int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);

View File

@@ -34,139 +34,11 @@
{
if (self = [super init]) {
self.uiscreen = screen;
/*
* A well up to date list of device info can be found here:
* https://github.com/lmirosevic/GBDeviceInfo/blob/master/GBDeviceInfo/GBDeviceInfo_iOS.m
*/
NSDictionary *devices = @{
@"iPhone1,1" : @163,
@"iPhone1,2" : @163,
@"iPhone2,1" : @163,
@"iPhone3,1" : @326,
@"iPhone3,2" : @326,
@"iPhone3,3" : @326,
@"iPhone4,1" : @326,
@"iPhone5,1" : @326,
@"iPhone5,2" : @326,
@"iPhone5,3" : @326,
@"iPhone5,4" : @326,
@"iPhone6,1" : @326,
@"iPhone6,2" : @326,
@"iPhone7,1" : @401,
@"iPhone7,2" : @326,
@"iPhone8,1" : @326,
@"iPhone8,2" : @401,
@"iPhone8,4" : @326,
@"iPhone9,1" : @326,
@"iPhone9,2" : @401,
@"iPhone9,3" : @326,
@"iPhone9,4" : @401,
@"iPhone10,1" : @326,
@"iPhone10,2" : @401,
@"iPhone10,3" : @458,
@"iPhone10,4" : @326,
@"iPhone10,5" : @401,
@"iPhone10,6" : @458,
@"iPhone11,2" : @458,
@"iPhone11,4" : @458,
@"iPhone11,6" : @458,
@"iPhone11,8" : @326,
@"iPhone12,1" : @326,
@"iPhone12,3" : @458,
@"iPhone12,5" : @458,
@"iPad1,1" : @132,
@"iPad2,1" : @132,
@"iPad2,2" : @132,
@"iPad2,3" : @132,
@"iPad2,4" : @132,
@"iPad2,5" : @163,
@"iPad2,6" : @163,
@"iPad2,7" : @163,
@"iPad3,1" : @264,
@"iPad3,2" : @264,
@"iPad3,3" : @264,
@"iPad3,4" : @264,
@"iPad3,5" : @264,
@"iPad3,6" : @264,
@"iPad4,1" : @264,
@"iPad4,2" : @264,
@"iPad4,3" : @264,
@"iPad4,4" : @326,
@"iPad4,5" : @326,
@"iPad4,6" : @326,
@"iPad4,7" : @326,
@"iPad4,8" : @326,
@"iPad4,9" : @326,
@"iPad5,1" : @326,
@"iPad5,2" : @326,
@"iPad5,3" : @264,
@"iPad5,4" : @264,
@"iPad6,3" : @264,
@"iPad6,4" : @264,
@"iPad6,7" : @264,
@"iPad6,8" : @264,
@"iPad6,11" : @264,
@"iPad6,12" : @264,
@"iPad7,1" : @264,
@"iPad7,2" : @264,
@"iPad7,3" : @264,
@"iPad7,4" : @264,
@"iPad7,5" : @264,
@"iPad7,6" : @264,
@"iPad7,11" : @264,
@"iPad7,12" : @264,
@"iPad8,1" : @264,
@"iPad8,2" : @264,
@"iPad8,3" : @264,
@"iPad8,4" : @264,
@"iPad8,5" : @264,
@"iPad8,6" : @264,
@"iPad8,7" : @264,
@"iPad8,8" : @264,
@"iPad11,1" : @326,
@"iPad11,2" : @326,
@"iPad11,3" : @326,
@"iPad11,4" : @326,
@"iPod1,1" : @163,
@"iPod2,1" : @163,
@"iPod3,1" : @163,
@"iPod4,1" : @326,
@"iPod5,1" : @326,
@"iPod7,1" : @326,
@"iPod9,1" : @326,
};
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceName =
[NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
id foundDPI = devices[deviceName];
if (foundDPI) {
self.screenDPI = (float)[foundDPI integerValue];
} else {
/*
* Estimate the DPI based on the screen scale multiplied by the base DPI for the device
* type (e.g. based on iPhone 1 and iPad 1)
*/
float scale = (float)screen.nativeScale;
float defaultDPI;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
defaultDPI = 132.0f;
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
defaultDPI = 163.0f;
} else {
defaultDPI = 160.0f;
}
self.screenDPI = scale * defaultDPI;
}
}
return self;
}
@synthesize uiscreen;
@synthesize screenDPI;
@end
@@ -451,26 +323,6 @@ int UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
return 0;
}
int UIKit_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
{
@autoreleasepool {
SDL_DisplayData *data = display->driverdata;
float dpi = data.screenDPI;
if (ddpi) {
*ddpi = dpi * (float)SDL_sqrt(2.0);
}
if (hdpi) {
*hdpi = dpi;
}
if (vdpi) {
*vdpi = dpi;
}
}
return 0;
}
int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
@autoreleasepool {

View File

@@ -93,7 +93,6 @@ static SDL_VideoDevice *UIKit_CreateDevice(void)
device->DestroyWindow = UIKit_DestroyWindow;
device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
device->GetDisplayUsableBounds = UIKit_GetDisplayUsableBounds;
device->GetDisplayPhysicalDPI = UIKit_GetDisplayPhysicalDPI;
device->GetWindowSizeInPixels = UIKit_GetWindowSizeInPixels;
#if SDL_IPHONE_KEYBOARD