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 65849e27e..a95dc45d6 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 class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh } } - /** - * 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 b5b9a1ebe..6eecb10d4 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 c20f7e81b..7288fb16e 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 6731c9a05..371e265c1 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 f6f8ae596..2ffa8e016 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 89feef7dd..e818327a2 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 eb6f9c4f4..a9f6680f3 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 2ec98a0d7..f45dbbfeb 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 3f8d8a87b..e88d94fe9 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 defc13810..818efcfbf 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 9bcf07f29..b0bc1db38 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 32668765e..bf702aab4 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 7cdee3497..e7d0f5926 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 28709809d..564ac9c71 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 e0fea1349..a43a6ee45 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 1031cf543..efc9a26c7 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -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; diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index 79879999e..2a04ea524 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 dc3c537f3..40b2d8d52 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 c673d22e5..3edc7a8e8 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -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 { diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index de6300f9f..faa257562 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -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 diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 92cfc9273..18038061b 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -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; diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index 4b82d5952..af0962c3a 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -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", diff --git a/src/video/windows/SDL_windowsmodes.h b/src/video/windows/SDL_windowsmodes.h index b1c809236..d58627143 100644 --- a/src/video/windows/SDL_windowsmodes.h +++ b/src/video/windows/SDL_windowsmodes.h @@ -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); diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index d010ce139..b59bbeb87 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -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 diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index c8e562b5d..d4d87ae01 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -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; diff --git a/src/video/x11/SDL_x11modes.h b/src/video/x11/SDL_x11modes.h index 8a86a8721..4a12a0744 100644 --- a/src/video/x11/SDL_x11modes.h +++ b/src/video/x11/SDL_x11modes.h @@ -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); diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index ff19d5048..463fb2cb2 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -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; diff --git a/test/testdisplayinfo.c b/test/testdisplayinfo.c index c328adbd4..85275fac8 100644 --- a/test/testdisplayinfo.c +++ b/test/testdisplayinfo.c @@ -53,19 +53,12 @@ int main(int argc, char *argv[]) for (i = 0; i < num_displays; i++) { SDL_DisplayID dpy = displays[i]; SDL_Rect rect = { 0, 0, 0, 0 }; - float ddpi, hdpi, vdpi; int m, num_modes = 0; SDL_GetDisplayBounds(dpy, &rect); modes = SDL_GetFullscreenDisplayModes(dpy, &num_modes); SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d, (%d, %d)), %d fullscreen modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes); - if (SDL_GetDisplayPhysicalDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError()); - } else { - SDL_Log(" DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi); - } - mode = SDL_GetCurrentDisplayMode(dpy); if (mode) { print_mode("CURRENT", mode);