]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
drm: Add simpledrm HiDPI display support
authorJanne Grunau <j@jannau.net>
Sat, 17 May 2025 06:57:06 +0000 (08:57 +0200)
committerJanne Grunau <j@jannau.net>
Sun, 13 Jul 2025 20:55:17 +0000 (22:55 +0200)
For devicetree based systems simpledrm might know the actual physical
display dimensions. Test if the reported connector width and height
result in a pixel density larger than 96 DPI. If that's the case
calculate the device scale instead of guessing it based on the
resolution.
This restores HiDPI scaling on 13-inch Apple silicon Macbooks with a
resolution of 2560x1600 (224 - 227 DPI) after commit 1421a9f6
("ply-utils: Increase threshold for guessed hiDPI scaling
to >= 2880x1620").

Signed-off-by: Janne Grunau <j@jannau.net>
src/libply/ply-utils.c
src/libply/ply-utils.h
src/plugins/renderers/drm/plugin.c

index 13d1f204f98fe50b48cc01d6ccb596c6ad654ff1..d8d28c08a6f423b44792c415d5aaa5e8914710a9 100644 (file)
@@ -1102,8 +1102,26 @@ ply_get_device_scale (uint32_t width,
 }
 
 int ply_guess_device_scale (uint32_t width,
-                            uint32_t height)
+                            uint32_t height,
+                            uint32_t width_mm,
+                            uint32_t height_mm)
 {
+        /* Simpledrm might know the actual physical dimensions of the its
+         * display. If it has no information it assumes 96 DPI. Calculate the
+         * pixel density to test if its larger than 96 DPI.
+         * Since DRM_MODE_RES_MM() truncates the the result add 1 to to width
+         * and height. This ensures that the calculated pixel density is only
+         * above 96 DPI if simpledrm has physical information.
+         */
+        uint32_t h_dpi = (width * 254) / ((width_mm + 1) * 10);
+        uint32_t v_dpi = (height * 254) / ((height_mm + 1) * 10);
+        if (h_dpi > 96 && v_dpi > 96) {
+                ply_trace ("simpledrm with valid dimensions (%u x %u mm)",
+                           width_mm, height_mm);
+                return get_device_scale (width, height, width_mm, height_mm,
+                                         false);
+        }
+
         guess_device_scale = true;
         return get_device_scale (width, height, 0, 0, true);
 }
index 058c7bff010bc47e10fbf5fe246870603f7cdccf..c9f74e1127749d8a99e4e4935515d72efca98a62 100644 (file)
@@ -166,7 +166,9 @@ int ply_get_device_scale (uint32_t width,
                           uint32_t height_mm);
 
 int ply_guess_device_scale (uint32_t width,
-                            uint32_t height);
+                            uint32_t height,
+                            uint32_t width_mm,
+                            uint32_t height_mm);
 
 void ply_get_kmsg_log_levels (int *current_log_level,
                               int *default_log_level);
index 88c5770bed0ba51b535f648b03e87b219c5924c5..bdd7fb211cb6f3c0fd853fef24a170051b3117b5 100644 (file)
@@ -1231,7 +1231,9 @@ get_output_info (ply_renderer_backend_t *backend,
         output->mode = *mode;
 
         if (backend->simpledrm)
-                output->device_scale = ply_guess_device_scale (mode->hdisplay, mode->vdisplay);
+                output->device_scale = ply_guess_device_scale (mode->hdisplay, mode->vdisplay,
+                                                               connector->mmWidth,
+                                                               connector->mmHeight);
         else
                 output->device_scale = ply_get_device_scale (mode->hdisplay, mode->vdisplay,
                                                              (!has_90_rotation) ? connector->mmWidth : connector->mmHeight,