mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-01-31 00:54:34 +00:00
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:
@@ -224,11 +224,6 @@ struct SDL_VideoDevice
|
||||
*/
|
||||
int (*GetDisplayUsableBounds)(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
|
||||
/*
|
||||
* Get the dots/pixels-per-inch of a display
|
||||
*/
|
||||
int (*GetDisplayPhysicalDPI)(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
|
||||
|
||||
/*
|
||||
* Get a list of the available display modes for a display.
|
||||
*/
|
||||
@@ -543,8 +538,6 @@ extern SDL_Window *SDL_GetFocusWindow(void);
|
||||
|
||||
extern SDL_bool SDL_ShouldAllowTopmost(void);
|
||||
|
||||
extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches);
|
||||
|
||||
extern void SDL_ToggleDragAndDropSupport(void);
|
||||
|
||||
/* This has been moved out of the public API, but is still available for now */
|
||||
|
||||
@@ -855,23 +855,6 @@ int SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect)
|
||||
return SDL_GetDisplayBounds(displayID, rect);
|
||||
}
|
||||
|
||||
int SDL_GetDisplayPhysicalDPI(SDL_DisplayID displayID, float *ddpi, float *hdpi, float *vdpi)
|
||||
{
|
||||
SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);
|
||||
|
||||
CHECK_DISPLAY_MAGIC(display, -1);
|
||||
|
||||
if (_this->GetDisplayPhysicalDPI) {
|
||||
if (_this->GetDisplayPhysicalDPI(_this, display, ddpi, hdpi, vdpi) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
}
|
||||
|
||||
SDL_DisplayOrientation SDL_GetDisplayOrientation(SDL_DisplayID displayID)
|
||||
{
|
||||
SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);
|
||||
@@ -4623,16 +4606,6 @@ int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *callbac
|
||||
return 0;
|
||||
}
|
||||
|
||||
float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
|
||||
{
|
||||
float den2 = hinches * hinches + vinches * vinches;
|
||||
if (den2 <= 0.0f) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return (float)(SDL_sqrt((double)hpix * (double)hpix + (double)vpix * (double)vpix) / SDL_sqrt((double)den2));
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions used by iOS application delegates
|
||||
*/
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
/* Initialization/Query functions */
|
||||
static int Android_VideoInit(_THIS);
|
||||
static void Android_VideoQuit(_THIS);
|
||||
int Android_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
|
||||
|
||||
#include "../SDL_egl_c.h"
|
||||
#define Android_GLES_GetProcAddress SDL_EGL_GetProcAddressInternal
|
||||
@@ -110,8 +109,6 @@ static SDL_VideoDevice *Android_CreateDevice(void)
|
||||
device->PumpEvents = Android_PumpEvents_NonBlocking;
|
||||
}
|
||||
|
||||
device->GetDisplayPhysicalDPI = Android_GetDisplayPhysicalDPI;
|
||||
|
||||
device->CreateSDLWindow = Android_CreateWindow;
|
||||
device->SetWindowTitle = Android_SetWindowTitle;
|
||||
device->SetWindowFullscreen = Android_SetWindowFullscreen;
|
||||
@@ -207,11 +204,6 @@ void Android_VideoQuit(_THIS)
|
||||
Android_QuitTouch();
|
||||
}
|
||||
|
||||
int Android_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
|
||||
{
|
||||
return Android_JNI_GetDisplayPhysicalDPI(ddpi, hdpi, vdpi);
|
||||
}
|
||||
|
||||
void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float density, float rate)
|
||||
{
|
||||
Android_SurfaceWidth = surfaceWidth;
|
||||
|
||||
@@ -37,7 +37,6 @@ extern void Cocoa_InitModes(_THIS);
|
||||
extern int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
extern int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
extern int Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
|
||||
extern int Cocoa_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
|
||||
extern int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
|
||||
extern void Cocoa_QuitModes(_THIS);
|
||||
|
||||
|
||||
@@ -406,73 +406,6 @@ int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Cocoa_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
|
||||
{
|
||||
@autoreleasepool {
|
||||
const float MM_IN_INCH = 25.4f;
|
||||
|
||||
SDL_DisplayData *data = display->driverdata;
|
||||
|
||||
/* we need the backingScaleFactor for Retina displays, which is only exposed through NSScreen, not CGDisplay, afaik, so find our screen... */
|
||||
NSArray *screens = [NSScreen screens];
|
||||
NSSize displayNativeSize;
|
||||
displayNativeSize.width = (int)CGDisplayPixelsWide(data->display);
|
||||
displayNativeSize.height = (int)CGDisplayPixelsHigh(data->display);
|
||||
|
||||
for (NSScreen *screen in screens) {
|
||||
const CGDirectDisplayID dpyid = (const CGDirectDisplayID)[[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
|
||||
if (dpyid == data->display) {
|
||||
/* Neither CGDisplayScreenSize(description's NSScreenNumber) nor [NSScreen backingScaleFactor] can calculate the correct dpi in macOS. E.g. backingScaleFactor is always 2 in all display modes for rMBP 16" */
|
||||
CFStringRef dmKeys[1] = { kCGDisplayShowDuplicateLowResolutionModes };
|
||||
CFBooleanRef dmValues[1] = { kCFBooleanTrue };
|
||||
CFDictionaryRef dmOptions = CFDictionaryCreate(kCFAllocatorDefault, (const void **)dmKeys, (const void **)dmValues, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
||||
CFArrayRef allDisplayModes = CGDisplayCopyAllDisplayModes(dpyid, dmOptions);
|
||||
CFIndex n = CFArrayGetCount(allDisplayModes);
|
||||
for (CFIndex i = 0; i < n; ++i) {
|
||||
CGDisplayModeRef m = (CGDisplayModeRef)CFArrayGetValueAtIndex(allDisplayModes, i);
|
||||
CGFloat width = CGDisplayModeGetPixelWidth(m);
|
||||
CGFloat height = CGDisplayModeGetPixelHeight(m);
|
||||
CGFloat HiDPIWidth = CGDisplayModeGetWidth(m);
|
||||
|
||||
// Only check 1x mode
|
||||
if (width == HiDPIWidth) {
|
||||
if (CGDisplayModeGetIOFlags(m) & kDisplayModeNativeFlag) {
|
||||
displayNativeSize.width = width;
|
||||
displayNativeSize.height = height;
|
||||
break;
|
||||
}
|
||||
|
||||
// Get the largest size even if kDisplayModeNativeFlag is not present e.g. iMac 27-Inch with 5K Retina
|
||||
if (width > displayNativeSize.width) {
|
||||
displayNativeSize.width = width;
|
||||
displayNativeSize.height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
CFRelease(allDisplayModes);
|
||||
CFRelease(dmOptions);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const CGSize displaySize = CGDisplayScreenSize(data->display);
|
||||
const int pixelWidth = displayNativeSize.width;
|
||||
const int pixelHeight = displayNativeSize.height;
|
||||
|
||||
if (ddpi) {
|
||||
*ddpi = (SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH));
|
||||
}
|
||||
if (hdpi) {
|
||||
*hdpi = (pixelWidth * MM_IN_INCH / displaySize.width);
|
||||
}
|
||||
if (vdpi) {
|
||||
*vdpi = (pixelHeight * MM_IN_INCH / displaySize.height);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
|
||||
{
|
||||
SDL_DisplayData *data = display->driverdata;
|
||||
|
||||
@@ -81,7 +81,6 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
|
||||
device->VideoQuit = Cocoa_VideoQuit;
|
||||
device->GetDisplayBounds = Cocoa_GetDisplayBounds;
|
||||
device->GetDisplayUsableBounds = Cocoa_GetDisplayUsableBounds;
|
||||
device->GetDisplayPhysicalDPI = Cocoa_GetDisplayPhysicalDPI;
|
||||
device->GetDisplayModes = Cocoa_GetDisplayModes;
|
||||
device->SetDisplayMode = Cocoa_SetDisplayMode;
|
||||
device->PumpEvents = Cocoa_PumpEvents;
|
||||
|
||||
@@ -39,7 +39,6 @@ static int Emscripten_VideoInit(_THIS);
|
||||
static int Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
|
||||
static void Emscripten_VideoQuit(_THIS);
|
||||
static int Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
static int Emscripten_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
|
||||
|
||||
static int Emscripten_CreateWindow(_THIS, SDL_Window *window);
|
||||
static void Emscripten_SetWindowSize(_THIS, SDL_Window *window);
|
||||
@@ -77,7 +76,6 @@ static SDL_VideoDevice *Emscripten_CreateDevice(void)
|
||||
device->VideoInit = Emscripten_VideoInit;
|
||||
device->VideoQuit = Emscripten_VideoQuit;
|
||||
device->GetDisplayUsableBounds = Emscripten_GetDisplayUsableBounds;
|
||||
device->GetDisplayPhysicalDPI = Emscripten_GetDisplayPhysicalDPI;
|
||||
device->SetDisplayMode = Emscripten_SetDisplayMode;
|
||||
|
||||
device->PumpEvents = Emscripten_PumpEvents;
|
||||
@@ -168,26 +166,6 @@ static int Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, S
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Emscripten_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi_out, float *hdpi_out, float *vdpi_out)
|
||||
{
|
||||
const float dpi_reference = 96.0f;
|
||||
float dpi;
|
||||
|
||||
dpi = (float)emscripten_get_device_pixel_ratio() * dpi_reference;
|
||||
|
||||
if (ddpi_out) {
|
||||
*ddpi_out = dpi;
|
||||
}
|
||||
if (hdpi_out) {
|
||||
*hdpi_out = dpi;
|
||||
}
|
||||
if (vdpi_out) {
|
||||
*vdpi_out = dpi;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Emscripten_PumpEvents(_THIS)
|
||||
{
|
||||
/* do nothing. */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -67,8 +67,6 @@ static void display_handle_done(void *data, struct wl_output *output);
|
||||
static int Wayland_VideoInit(_THIS);
|
||||
|
||||
static int Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
static int Wayland_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
|
||||
|
||||
static void Wayland_VideoQuit(_THIS);
|
||||
|
||||
/* Find out what class name we should use
|
||||
@@ -207,7 +205,6 @@ static SDL_VideoDevice *Wayland_CreateDevice(void)
|
||||
device->VideoInit = Wayland_VideoInit;
|
||||
device->VideoQuit = Wayland_VideoQuit;
|
||||
device->GetDisplayBounds = Wayland_GetDisplayBounds;
|
||||
device->GetDisplayPhysicalDPI = Wayland_GetDisplayPhysicalDPI;
|
||||
device->GetWindowWMInfo = Wayland_GetWindowWMInfo;
|
||||
device->SuspendScreenSaver = Wayland_SuspendScreenSaver;
|
||||
|
||||
@@ -636,23 +633,6 @@ static void display_handle_done(void *data,
|
||||
AddEmulatedModes(driverdata, native_mode.pixel_w, native_mode.pixel_h);
|
||||
}
|
||||
|
||||
/* Calculate the display DPI */
|
||||
if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) {
|
||||
driverdata->hdpi = driverdata->physical_height ? (((float)driverdata->pixel_height) * 25.4f / driverdata->physical_height) : 0.0f;
|
||||
driverdata->vdpi = driverdata->physical_width ? (((float)driverdata->pixel_width) * 25.4f / driverdata->physical_width) : 0.0f;
|
||||
driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->pixel_height,
|
||||
driverdata->pixel_width,
|
||||
((float)driverdata->physical_height) / 25.4f,
|
||||
((float)driverdata->physical_width) / 25.4f);
|
||||
} else {
|
||||
driverdata->hdpi = driverdata->physical_width ? (((float)driverdata->pixel_width) * 25.4f / driverdata->physical_width) : 0.0f;
|
||||
driverdata->vdpi = driverdata->physical_height ? (((float)driverdata->pixel_height) * 25.4f / driverdata->physical_height) : 0.0f;
|
||||
driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->pixel_width,
|
||||
driverdata->pixel_height,
|
||||
((float)driverdata->physical_width) / 25.4f,
|
||||
((float)driverdata->physical_height) / 25.4f);
|
||||
}
|
||||
|
||||
if (driverdata->display == 0) {
|
||||
/* First time getting display info, create the VideoDisplay */
|
||||
SDL_bool send_event = driverdata->videodata->initializing ? SDL_FALSE : SDL_TRUE;
|
||||
@@ -988,23 +968,6 @@ static int Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Wayland_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
|
||||
{
|
||||
SDL_DisplayData *driverdata = display->driverdata;
|
||||
|
||||
if (ddpi) {
|
||||
*ddpi = driverdata->ddpi;
|
||||
}
|
||||
if (hdpi) {
|
||||
*hdpi = driverdata->hdpi;
|
||||
}
|
||||
if (vdpi) {
|
||||
*vdpi = driverdata->vdpi;
|
||||
}
|
||||
|
||||
return driverdata->ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
|
||||
}
|
||||
|
||||
static void Wayland_VideoCleanup(_THIS)
|
||||
{
|
||||
SDL_VideoData *data = _this->driverdata;
|
||||
|
||||
@@ -499,62 +499,32 @@ int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WIN_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi_out, float *hdpi_out, float *vdpi_out)
|
||||
static int WIN_GetDisplayDPI(SDL_DisplayID displayID, int *dpi)
|
||||
{
|
||||
const SDL_DisplayData *displaydata = display->driverdata;
|
||||
const SDL_VideoData *videodata = display->device->driverdata;
|
||||
float hdpi = 0, vdpi = 0, ddpi = 0;
|
||||
const SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);
|
||||
const SDL_DisplayData *displaydata = display ? display->driverdata : NULL;
|
||||
const SDL_VideoData *videodata = display ? display->device->driverdata : NULL;
|
||||
|
||||
if (videodata->GetDpiForMonitor) {
|
||||
UINT hdpi_uint, vdpi_uint;
|
||||
// Windows 8.1+ codepath
|
||||
if (videodata->GetDpiForMonitor(displaydata->MonitorHandle, MDT_EFFECTIVE_DPI, &hdpi_uint, &vdpi_uint) == S_OK) {
|
||||
// GetDpiForMonitor docs promise to return the same hdpi/vdpi
|
||||
hdpi = (float)hdpi_uint;
|
||||
vdpi = (float)hdpi_uint;
|
||||
ddpi = (float)hdpi_uint;
|
||||
} else {
|
||||
return SDL_SetError("GetDpiForMonitor failed");
|
||||
*dpi = 0;
|
||||
|
||||
if (videodata && videodata->GetDpiForMonitor) {
|
||||
/* Windows 8.1 + codepath */
|
||||
UINT xdpi, ydpi;
|
||||
videodata->GetDpiForMonitor(displaydata->MonitorHandle, MDT_EFFECTIVE_DPI, &xdpi, &ydpi);
|
||||
*dpi = (int)xdpi; /* xdpi and hdpi are the same value */
|
||||
}
|
||||
if (*dpi == 0) {
|
||||
/* Window 8.0 and below: same DPI for all monitors */
|
||||
HDC hdc = GetDC(NULL);
|
||||
if (hdc) {
|
||||
*dpi = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
ReleaseDC(NULL, hdc);
|
||||
}
|
||||
} else {
|
||||
// Window 8.0 and below: same DPI for all monitors.
|
||||
HDC hdc;
|
||||
int hdpi_int, vdpi_int, hpoints, vpoints, hpix, vpix;
|
||||
float hinches, vinches;
|
||||
|
||||
hdc = GetDC(NULL);
|
||||
if (hdc == NULL) {
|
||||
return SDL_SetError("GetDC failed");
|
||||
}
|
||||
hdpi_int = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||
vdpi_int = GetDeviceCaps(hdc, LOGPIXELSY);
|
||||
ReleaseDC(NULL, hdc);
|
||||
|
||||
hpoints = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
||||
vpoints = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
||||
|
||||
hpix = MulDiv(hpoints, hdpi_int, 96);
|
||||
vpix = MulDiv(vpoints, vdpi_int, 96);
|
||||
|
||||
hinches = (float)hpoints / 96.0f;
|
||||
vinches = (float)vpoints / 96.0f;
|
||||
|
||||
hdpi = (float)hdpi_int;
|
||||
vdpi = (float)vdpi_int;
|
||||
ddpi = SDL_ComputeDiagonalDPI(hpix, vpix, hinches, vinches);
|
||||
}
|
||||
|
||||
if (ddpi_out) {
|
||||
*ddpi_out = ddpi;
|
||||
if (*dpi == 0) {
|
||||
return SDL_SetError("Couldn't get display DPI");
|
||||
}
|
||||
if (hdpi_out) {
|
||||
*hdpi_out = hdpi;
|
||||
}
|
||||
if (vdpi_out) {
|
||||
*vdpi_out = vdpi;
|
||||
}
|
||||
|
||||
return ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WIN_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
@@ -603,7 +573,7 @@ void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int *
|
||||
const SDL_VideoData *videodata;
|
||||
SDL_DisplayID displayID;
|
||||
SDL_Rect bounds;
|
||||
float ddpi, hdpi, vdpi;
|
||||
int dpi;
|
||||
SDL_Point point;
|
||||
|
||||
point.x = (int)x;
|
||||
@@ -628,17 +598,17 @@ void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int *
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
if (SDL_GetDisplayBounds(displayID, &bounds) < 0 || SDL_GetDisplayPhysicalDPI(displayID, &ddpi, &hdpi, &vdpi) < 0) {
|
||||
if (SDL_GetDisplayBounds(displayID, &bounds) < 0 || WIN_GetDisplayDPI(displayID, &dpi) < 0) {
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
if (dpiOut) {
|
||||
*dpiOut = (int)ddpi;
|
||||
*dpiOut = dpi;
|
||||
}
|
||||
|
||||
/* Undo the DPI-scaling within the monitor bounds to convert back to pixels */
|
||||
*xOut = bounds.x + SDL_lroundf(((x - bounds.x) * ddpi) / 96.0f);
|
||||
*yOut = bounds.y + SDL_lroundf(((y - bounds.y) * ddpi) / 96.0f);
|
||||
*xOut = bounds.x + SDL_lroundf(((x - bounds.x) * dpi) / 96.0f);
|
||||
*yOut = bounds.y + SDL_lroundf(((y - bounds.y) * dpi) / 96.0f);
|
||||
|
||||
#ifdef HIGHDPI_DEBUG_VERBOSE
|
||||
SDL_Log("WIN_ScreenPointFromSDL: (%g, %g) points -> (%d x %d) pixels, using %g DPI monitor",
|
||||
@@ -674,7 +644,7 @@ void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut)
|
||||
int i;
|
||||
SDL_DisplayID displayID;
|
||||
SDL_Rect bounds;
|
||||
float ddpi, hdpi, vdpi;
|
||||
int dpi;
|
||||
|
||||
if (videodevice == NULL || !videodevice->driverdata) {
|
||||
return;
|
||||
@@ -704,13 +674,13 @@ void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut)
|
||||
}
|
||||
|
||||
/* Get SDL display properties */
|
||||
if (SDL_GetDisplayBounds(displayID, &bounds) < 0 || SDL_GetDisplayPhysicalDPI(displayID, &ddpi, &hdpi, &vdpi) < 0) {
|
||||
if (SDL_GetDisplayBounds(displayID, &bounds) < 0 || WIN_GetDisplayDPI(displayID, &dpi) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Convert the point's offset within the monitor from pixels to DPI-scaled points */
|
||||
*xOut = (float)bounds.x + ((float)(x - bounds.x) * 96.0f) / ddpi;
|
||||
*yOut = (float)bounds.y + ((float)(y - bounds.y) * 96.0f) / ddpi;
|
||||
*xOut = (float)bounds.x + ((float)(x - bounds.x) * 96.0f) / dpi;
|
||||
*yOut = (float)bounds.y + ((float)(y - bounds.y) * 96.0f) / dpi;
|
||||
|
||||
#ifdef HIGHDPI_DEBUG_VERBOSE
|
||||
SDL_Log("WIN_ScreenPointToSDL: (%d, %d) pixels -> (%g x %g) points, using %g DPI monitor",
|
||||
|
||||
@@ -43,7 +43,6 @@ extern void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut);
|
||||
extern void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int *dpiOut);
|
||||
extern void WIN_ScreenPointToSDL(int *x, int *y);
|
||||
extern void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut);
|
||||
extern int WIN_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
|
||||
extern int WIN_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
|
||||
extern int WIN_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
|
||||
extern void WIN_RefreshDisplays(_THIS);
|
||||
|
||||
@@ -156,7 +156,6 @@ static SDL_VideoDevice *WIN_CreateDevice(void)
|
||||
device->RefreshDisplays = WIN_RefreshDisplays;
|
||||
device->GetDisplayBounds = WIN_GetDisplayBounds;
|
||||
device->GetDisplayUsableBounds = WIN_GetDisplayUsableBounds;
|
||||
device->GetDisplayPhysicalDPI = WIN_GetDisplayPhysicalDPI;
|
||||
device->GetDisplayModes = WIN_GetDisplayModes;
|
||||
device->SetDisplayMode = WIN_SetDisplayMode;
|
||||
#endif
|
||||
|
||||
@@ -369,9 +369,6 @@ static int X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput output
|
||||
displaydata->screen = screen;
|
||||
displaydata->visual = vinfo.visual;
|
||||
displaydata->depth = vinfo.depth;
|
||||
displaydata->hdpi = display_mm_width ? (((float)mode.pixel_w) * 25.4f / display_mm_width) : 0.0f;
|
||||
displaydata->vdpi = display_mm_height ? (((float)mode.pixel_h) * 25.4f / display_mm_height) : 0.0f;
|
||||
displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.pixel_w, mode.pixel_h, ((float)display_mm_width) / 25.4f, ((float)display_mm_height) / 25.4f);
|
||||
displaydata->scanline_pad = scanline_pad;
|
||||
displaydata->x = display_x;
|
||||
displaydata->y = display_y;
|
||||
@@ -522,29 +519,6 @@ static int X11_InitModes_XRandR(_THIS)
|
||||
}
|
||||
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
|
||||
|
||||
static int GetXftDPI(Display *dpy)
|
||||
{
|
||||
char *xdefault_resource;
|
||||
int xft_dpi, err;
|
||||
|
||||
xdefault_resource = X11_XGetDefault(dpy, "Xft", "dpi");
|
||||
|
||||
if (xdefault_resource == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* It's possible for SDL_atoi to call SDL_strtol, if it fails due to a
|
||||
* overflow or an underflow, it will return LONG_MAX or LONG_MIN and set
|
||||
* errno to ERANGE. So we need to check for this so we dont get crazy dpi
|
||||
* values
|
||||
*/
|
||||
xft_dpi = SDL_atoi(xdefault_resource);
|
||||
err = errno;
|
||||
|
||||
return err == ERANGE ? 0 : xft_dpi;
|
||||
}
|
||||
|
||||
/* This is used if there's no better functionality--like XRandR--to use.
|
||||
It won't attempt to supply different display modes at all, but it can
|
||||
enumerate the current displays and their current sizes. */
|
||||
@@ -555,7 +529,7 @@ static int X11_InitModes_StdXlib(_THIS)
|
||||
Display *dpy = data->display;
|
||||
const int default_screen = DefaultScreen(dpy);
|
||||
Screen *screen = ScreenOfDisplay(dpy, default_screen);
|
||||
int display_mm_width, display_mm_height, xft_dpi, scanline_pad, n, i;
|
||||
int scanline_pad, n, i;
|
||||
SDL_DisplayModeData *modedata;
|
||||
SDL_DisplayData *displaydata;
|
||||
SDL_DisplayMode mode;
|
||||
@@ -592,21 +566,9 @@ static int X11_InitModes_StdXlib(_THIS)
|
||||
}
|
||||
mode.driverdata = modedata;
|
||||
|
||||
display_mm_width = WidthMMOfScreen(screen);
|
||||
display_mm_height = HeightMMOfScreen(screen);
|
||||
|
||||
displaydata->screen = default_screen;
|
||||
displaydata->visual = vinfo.visual;
|
||||
displaydata->depth = vinfo.depth;
|
||||
displaydata->hdpi = display_mm_width ? (((float)mode.pixel_w) * 25.4f / display_mm_width) : 0.0f;
|
||||
displaydata->vdpi = display_mm_height ? (((float)mode.pixel_h) * 25.4f / display_mm_height) : 0.0f;
|
||||
displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.pixel_w, mode.pixel_h, ((float)display_mm_width) / 25.4f, ((float)display_mm_height) / 25.4f);
|
||||
|
||||
xft_dpi = GetXftDPI(dpy);
|
||||
if (xft_dpi > 0) {
|
||||
displaydata->hdpi = (float)xft_dpi;
|
||||
displaydata->vdpi = (float)xft_dpi;
|
||||
}
|
||||
|
||||
scanline_pad = SDL_BYTESPERPIXEL(pixelformat) * 8;
|
||||
pixmapformats = X11_XListPixmapFormats(dpy, &n);
|
||||
@@ -824,23 +786,6 @@ int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay *sdl_display, SDL_Rect *rect)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int X11_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *sdl_display, float *ddpi, float *hdpi, float *vdpi)
|
||||
{
|
||||
SDL_DisplayData *data = sdl_display->driverdata;
|
||||
|
||||
if (ddpi) {
|
||||
*ddpi = data->ddpi;
|
||||
}
|
||||
if (hdpi) {
|
||||
*hdpi = data->hdpi;
|
||||
}
|
||||
if (vdpi) {
|
||||
*vdpi = data->vdpi;
|
||||
}
|
||||
|
||||
return data->ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
|
||||
}
|
||||
|
||||
int X11_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *sdl_display, SDL_Rect *rect)
|
||||
{
|
||||
SDL_VideoData *data = _this->driverdata;
|
||||
|
||||
@@ -31,9 +31,6 @@ struct SDL_DisplayData
|
||||
int scanline_pad;
|
||||
int x;
|
||||
int y;
|
||||
float ddpi;
|
||||
float hdpi;
|
||||
float vdpi;
|
||||
|
||||
SDL_bool use_xrandr;
|
||||
|
||||
@@ -63,7 +60,6 @@ extern Uint32 X11_GetPixelFormatFromVisualInfo(Display *display,
|
||||
XVisualInfo *vinfo);
|
||||
extern int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay *sdl_display, SDL_Rect *rect);
|
||||
extern int X11_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *sdl_display, SDL_Rect *rect);
|
||||
extern int X11_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *sdl_display, float *ddpi, float *hdpi, float *vdpi);
|
||||
|
||||
#if SDL_VIDEO_DRIVER_X11_XRANDR
|
||||
extern void X11_HandleXRandREvent(_THIS, const XEvent *xevent);
|
||||
|
||||
@@ -214,7 +214,6 @@ static SDL_VideoDevice *X11_CreateDevice(void)
|
||||
device->GetDisplayModes = X11_GetDisplayModes;
|
||||
device->GetDisplayBounds = X11_GetDisplayBounds;
|
||||
device->GetDisplayUsableBounds = X11_GetDisplayUsableBounds;
|
||||
device->GetDisplayPhysicalDPI = X11_GetDisplayPhysicalDPI;
|
||||
device->GetWindowICCProfile = X11_GetWindowICCProfile;
|
||||
device->SetDisplayMode = X11_SetDisplayMode;
|
||||
device->SuspendScreenSaver = X11_SuspendScreenSaver;
|
||||
|
||||
Reference in New Issue
Block a user