From 824b9b0a58b39305c94de0ac37a7fcca634d6d55 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 8 Feb 2023 15:07:13 -0800
Subject: [PATCH] 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.
---
.../main/java/org/libsdl/app/SDLActivity.java | 7 -
docs/README-migration.md | 2 +-
include/SDL3/SDL_oldnames.h | 2 -
include/SDL3/SDL_video.h | 30 ----
src/core/android/SDL_android.c | 34 ----
src/core/android/SDL_android.h | 1 -
src/dynapi/SDL_dynapi.sym | 1 -
src/dynapi/SDL_dynapi_overrides.h | 1 -
src/dynapi/SDL_dynapi_procs.h | 1 -
src/test/SDL_test_common.c | 13 --
src/video/SDL_sysvideo.h | 7 -
src/video/SDL_video.c | 27 ----
src/video/android/SDL_androidvideo.c | 8 -
src/video/cocoa/SDL_cocoamodes.h | 1 -
src/video/cocoa/SDL_cocoamodes.m | 67 --------
src/video/cocoa/SDL_cocoavideo.m | 1 -
src/video/emscripten/SDL_emscriptenvideo.c | 22 ---
src/video/uikit/SDL_uikitmodes.h | 2 -
src/video/uikit/SDL_uikitmodes.m | 148 ------------------
src/video/uikit/SDL_uikitvideo.m | 1 -
src/video/wayland/SDL_waylandvideo.c | 37 -----
src/video/windows/SDL_windowsmodes.c | 92 ++++-------
src/video/windows/SDL_windowsmodes.h | 1 -
src/video/windows/SDL_windowsvideo.c | 1 -
src/video/x11/SDL_x11modes.c | 57 +------
src/video/x11/SDL_x11modes.h | 4 -
src/video/x11/SDL_x11video.c | 1 -
test/testdisplayinfo.c | 7 -
28 files changed, 33 insertions(+), 543 deletions(-)
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 65849e27e4ad..a95dc45d67e3 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -1198,13 +1198,6 @@ public static boolean isDeXMode() {
}
}
- /**
- * This method is called by SDL using JNI.
- */
- public static DisplayMetrics getDisplayDPI() {
- return getContext().getResources().getDisplayMetrics();
- }
-
/**
* This method is called by SDL using JNI.
*/
diff --git a/docs/README-migration.md b/docs/README-migration.md
index b5b9a1ebeb5b..6eecb10d4b38 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1051,7 +1051,6 @@ SDL_GL_GetDrawableSize() has been removed. SDL_GetWindowSizeInPixels() can be us
The following functions have been renamed:
* SDL_GetClosestDisplayMode() => SDL_GetClosestFullscreenDisplayMode()
-* SDL_GetDisplayDPI() => SDL_GetDisplayPhysicalDPI()
* SDL_GetPointDisplayIndex() => SDL_GetDisplayForPoint()
* SDL_GetRectDisplayIndex() => SDL_GetDisplayForRect()
* SDL_GetWindowDisplayIndex() => SDL_GetDisplayForWindow()
@@ -1060,6 +1059,7 @@ The following functions have been renamed:
The following functions have been removed:
* SDL_GetClosestFullscreenDisplayMode()
+* SDL_GetDisplayDPI() - not reliable across platforms, approximately replaced by multiplying `display_scale` in the structure returned by SDL_GetDesktopDisplayMode() times 160 on iPhone and Android, and 96 on other platforms.
* SDL_GetDisplayMode()
* SDL_GetNumDisplayModes() - replaced with SDL_GetFullscreenDisplayModes()
* SDL_GetNumVideoDisplays() - replaced with SDL_GetDisplays()
diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h
index c20f7e81b886..7288fb16e37e 100644
--- a/include/SDL3/SDL_oldnames.h
+++ b/include/SDL3/SDL_oldnames.h
@@ -425,7 +425,6 @@
/* ##SDL_video.h */
#define SDL_GetClosestDisplayMode SDL_GetClosestFullscreenDisplayMode
-#define SDL_GetDisplayDPI SDL_GetDisplayPhysicalDPI
#define SDL_GetPointDisplayIndex SDL_GetDisplayForPoint
#define SDL_GetRectDisplayIndex SDL_GetDisplayForRect
#define SDL_GetWindowDisplayIndex SDL_GetDisplayForWindow
@@ -822,7 +821,6 @@
/* ##SDL_video.h */
#define SDL_GetClosestDisplayMode SDL_GetClosestDisplayMode_renamed_SDL_GetClosestFullscreenDisplayMode
-#define SDL_GetDisplayDPI SDL_GetDisplayDPI_renamed_SDL_GetDisplayPhysicalDPI
#define SDL_GetPointDisplayIndex SDL_GetPointDisplayIndex_renamed_SDL_GetDisplayForPoint
#define SDL_GetRectDisplayIndex SDL_GetRectDisplayIndex_renamed_SDL_GetDisplayForRect
#define SDL_GetWindowDisplayIndex SDL_GetWindowDisplayIndex_renamed_SDL_GetDisplayForWindow
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index 6731c9a058d8..371e265c1625 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -375,36 +375,6 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Re
*/
extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect);
-/**
- * Get the dots/pixels-per-inch for a display.
- *
- * Diagonal, horizontal and vertical DPI can all be optionally returned if the
- * appropriate parameter is non-NULL.
- *
- * **WARNING**: This reports the DPI that the hardware reports, and it is not
- * always reliable! It is almost always better to use SDL_GetWindowSize() to
- * find the window size, which might be in logical points instead of pixels,
- * and then SDL_GetWindowSizeInPixels() or SDL_GetRendererOutputSize(), and
- * compare the two values to get an actual scaling value between the two. We
- * will be rethinking how high-dpi details should be managed in SDL3 to make
- * things more consistent, reliable, and clear.
- *
- * \param displayID the instance ID of the display to query
- * \param ddpi a pointer filled in with the diagonal DPI of the display; may
- * be NULL
- * \param hdpi a pointer filled in with the horizontal DPI of the display; may
- * be NULL
- * \param vdpi a pointer filled in with the vertical DPI of the display; may
- * be NULL
- * \returns 0 on success or a negative error code on failure; call
- * SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetDisplays
- */
-extern DECLSPEC int SDLCALL SDL_GetDisplayPhysicalDPI(SDL_DisplayID displayID, float *ddpi, float *hdpi, float *vdpi);
-
/**
* Get the orientation of a display.
*
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index f6f8ae596554..2ffa8e016bac 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -304,7 +304,6 @@ static jmethodID midClipboardSetText;
static jmethodID midCreateCustomCursor;
static jmethodID midDestroyCustomCursor;
static jmethodID midGetContext;
-static jmethodID midGetDisplayPhysicalDPI;
static jmethodID midGetManifestEnvironmentVariables;
static jmethodID midGetNativeSurface;
static jmethodID midInitTouch;
@@ -593,7 +592,6 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
midCreateCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "createCustomCursor", "([IIIII)I");
midDestroyCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "destroyCustomCursor", "(I)V");
midGetContext = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
- midGetDisplayPhysicalDPI = (*env)->GetStaticMethodID(env, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
midGetManifestEnvironmentVariables = (*env)->GetStaticMethodID(env, mActivityClass, "getManifestEnvironmentVariables", "()Z");
midGetNativeSurface = (*env)->GetStaticMethodID(env, mActivityClass, "getNativeSurface", "()Landroid/view/Surface;");
midInitTouch = (*env)->GetStaticMethodID(env, mActivityClass, "initTouch", "()V");
@@ -624,7 +622,6 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
!midCreateCustomCursor ||
!midDestroyCustomCursor ||
!midGetContext ||
- !midGetDisplayPhysicalDPI ||
!midGetManifestEnvironmentVariables ||
!midGetNativeSurface ||
!midInitTouch ||
@@ -1650,37 +1647,6 @@ SDL_DisplayOrientation Android_JNI_GetDisplayOrientation(void)
return displayOrientation;
}
-int Android_JNI_GetDisplayPhysicalDPI(float *ddpi, float *xdpi, float *ydpi)
-{
- JNIEnv *env = Android_JNI_GetEnv();
-
- jobject jDisplayObj = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetDisplayPhysicalDPI);
- jclass jDisplayClass = (*env)->GetObjectClass(env, jDisplayObj);
-
- jfieldID fidXdpi = (*env)->GetFieldID(env, jDisplayClass, "xdpi", "F");
- jfieldID fidYdpi = (*env)->GetFieldID(env, jDisplayClass, "ydpi", "F");
- jfieldID fidDdpi = (*env)->GetFieldID(env, jDisplayClass, "densityDpi", "I");
-
- float nativeXdpi = (*env)->GetFloatField(env, jDisplayObj, fidXdpi);
- float nativeYdpi = (*env)->GetFloatField(env, jDisplayObj, fidYdpi);
- int nativeDdpi = (*env)->GetIntField(env, jDisplayObj, fidDdpi);
-
- (*env)->DeleteLocalRef(env, jDisplayObj);
- (*env)->DeleteLocalRef(env, jDisplayClass);
-
- if (ddpi) {
- *ddpi = (float)nativeDdpi;
- }
- if (xdpi) {
- *xdpi = nativeXdpi;
- }
- if (ydpi) {
- *ydpi = nativeYdpi;
- }
-
- return 0;
-}
-
void *Android_JNI_GetAudioBuffer(void)
{
return audioBufferPinned;
diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h
index 89feef7dd823..e818327a2ad0 100644
--- a/src/core/android/SDL_android.h
+++ b/src/core/android/SDL_android.h
@@ -44,7 +44,6 @@ extern SDL_bool Android_JNI_IsScreenKeyboardShown(void);
extern ANativeWindow *Android_JNI_GetNativeWindow(void);
extern SDL_DisplayOrientation Android_JNI_GetDisplayOrientation(void);
-extern int Android_JNI_GetDisplayPhysicalDPI(float *ddpi, float *xdpi, float *ydpi);
/* Audio support */
extern void Android_DetectDevices(void);
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index eb6f9c4f441f..a9f6680f36bb 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -162,7 +162,6 @@ SDL3_0.0.0 {
SDL_GetDefaultCursor;
SDL_GetDesktopDisplayMode;
SDL_GetDisplayBounds;
- SDL_GetDisplayPhysicalDPI;
SDL_GetDisplayForPoint;
SDL_GetDisplayForRect;
SDL_GetDisplayName;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 2ec98a0d7f32..f45dbbfebe3f 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -187,7 +187,6 @@
#define SDL_GetDefaultCursor SDL_GetDefaultCursor_REAL
#define SDL_GetDesktopDisplayMode SDL_GetDesktopDisplayMode_REAL
#define SDL_GetDisplayBounds SDL_GetDisplayBounds_REAL
-#define SDL_GetDisplayPhysicalDPI SDL_GetDisplayPhysicalDPI_REAL
#define SDL_GetDisplayForPoint SDL_GetDisplayForPoint_REAL
#define SDL_GetDisplayForRect SDL_GetDisplayForRect_REAL
#define SDL_GetDisplayName SDL_GetDisplayName_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 3f8d8a87b70f..e88d94fe9719 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -261,7 +261,6 @@ SDL_DYNAPI_PROC(int,SDL_GetDefaultAudioInfo,(char **a, SDL_AudioSpec *b, int c),
SDL_DYNAPI_PROC(SDL_Cursor*,SDL_GetDefaultCursor,(void),(),return)
SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetDesktopDisplayMode,(SDL_DisplayID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetDisplayBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return)
-SDL_DYNAPI_PROC(int,SDL_GetDisplayPhysicalDPI,(SDL_DisplayID a, float *b, float *c, float *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForPoint,(const SDL_Point *a),(a),return)
SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForRect,(const SDL_Rect *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetDisplayName,(SDL_DisplayID a),(a),return)
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index defc138104cc..818efcfbf6e5 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -1187,8 +1187,6 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
if (state->verbose & VERBOSE_MODES) {
SDL_DisplayID *displays;
SDL_Rect bounds, usablebounds;
- float hdpi = 0;
- float vdpi = 0;
const SDL_DisplayMode **modes;
const SDL_DisplayMode *mode;
int bpp;
@@ -1209,11 +1207,8 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
SDL_zero(usablebounds);
SDL_GetDisplayUsableBounds(displayID, &usablebounds);
- SDL_GetDisplayPhysicalDPI(displayID, NULL, &hdpi, &vdpi);
-
SDL_Log("Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
SDL_Log("Usable bounds: %dx%d at %d,%d\n", usablebounds.w, usablebounds.h, usablebounds.x, usablebounds.y);
- SDL_Log("DPI: %gx%g\n", hdpi, vdpi);
mode = SDL_GetDesktopDisplayMode(displayID);
SDL_GetMasksForPixelFormatEnum(mode->format, &bpp, &Rmask, &Gmask,
@@ -2301,7 +2296,6 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
float fx, fy;
SDL_Rect rect;
const SDL_DisplayMode *mode;
- float ddpi, hdpi, vdpi;
float scaleX, scaleY;
Uint32 flags;
SDL_DisplayID windowDisplayID = SDL_GetDisplayForWindow(window);
@@ -2437,13 +2431,6 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
textY += lineHeight;
}
- if (0 == SDL_GetDisplayPhysicalDPI(windowDisplayID, &ddpi, &hdpi, &vdpi)) {
- (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayPhysicalDPI: ddpi: %g, hdpi: %g, vdpi: %g",
- ddpi, hdpi, vdpi);
- SDLTest_DrawString(renderer, 0.0f, textY, text);
- textY += lineHeight;
- }
-
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayOrientation: ");
SDLTest_PrintDisplayOrientation(text, sizeof text, SDL_GetDisplayOrientation(windowDisplayID));
SDLTest_DrawString(renderer, 0.0f, textY, text);
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 9bcf07f29a5a..b0bc1db3866c 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -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 */
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 32668765ed49..bf702aab4acb 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -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
*/
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index 7cdee3497f46..e7d0f592646a 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -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;
diff --git a/src/video/cocoa/SDL_cocoamodes.h b/src/video/cocoa/SDL_cocoamodes.h
index 28709809d686..564ac9c71b14 100644
--- a/src/video/cocoa/SDL_cocoamodes.h
+++ b/src/video/cocoa/SDL_cocoamodes.h
@@ -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);
diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m
index e0fea13493dd..a43a6ee45f99 100644
--- a/src/video/cocoa/SDL_cocoamodes.m
+++ b/src/video/cocoa/SDL_cocoamodes.m
@@ -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;
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index 1031cf5435a1..efc9a26c751e 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -81,7 +81,6 @@ static void Cocoa_DeleteDevice(SDL_VideoDevice *device)
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;
diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c
index 79879999eb74..2a04ea52447a 100644
--- a/src/video/emscripten/SDL_emscriptenvideo.c
+++ b/src/video/emscripten/SDL_emscriptenvideo.c
@@ -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. */
diff --git a/src/video/uikit/SDL_uikitmodes.h b/src/video/uikit/SDL_uikitmodes.h
index dc3c537f38b7..40b2d8d528b4 100644
--- a/src/video/uikit/SDL_uikitmodes.h
+++ b/src/video/uikit/SDL_uikitmodes.h
@@ -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);
diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m
index c673d22e53e7..3edc7a8e848e 100644
--- a/src/video/uikit/SDL_uikitmodes.m
+++ b/src/video/uikit/SDL_uikitmodes.m
@@ -34,139 +34,11 @@ - (instancetype)initWithScreen:(UIScreen *)screen
{
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
(Patch may be truncated, please check the link at the top of this post.)