sdl2-compat: Actually the DPI is the combination of the pixel density and content scale

From 34e0e6f5752271f8c409ff8cf85c95dbac91cb6b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 19 May 2023 06:33:34 -0700
Subject: [PATCH] Actually the DPI is the combination of the pixel density and
 content scale

---
 src/sdl2_compat.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index ef8716e..78ebea2 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -3789,7 +3789,10 @@ SDL_GetNumDisplayModes(int displayIndex)
 DECLSPEC int SDLCALL
 SDL_GetDisplayDPI(int displayIndex, float *ddpi, float *hdpi, float *vdpi)
 {
-    float content_scale = SDL3_GetDisplayContentScale(Display_IndexToID(displayIndex));
+    SDL_DisplayID displayID = Display_IndexToID(displayIndex);
+    const SDL_DisplayMode *dp = SDL3_GetDesktopDisplayMode(displayID);
+    float pixel_density = dp ? dp->pixel_density : 1.0f;
+    float content_scale = SDL3_GetDisplayContentScale(displayID);
     float dpi;
 
     if (content_scale == 0.0f) {
@@ -3797,9 +3800,9 @@ SDL_GetDisplayDPI(int displayIndex, float *ddpi, float *hdpi, float *vdpi)
     }
 
 #if defined(__ANDROID__) || defined(__IOS__)
-    dpi = content_scale * 160.0f;
+    dpi = pixel_density * content_scale * 160.0f;
 #else
-    dpi = content_scale * 96.0f;
+    dpi = pixel_density * content_scale * 96.0f;
 #endif
 
     if (hdpi) {