]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
utils: Add ply_guess_device_scale () helper
authorHans de Goede <hdegoede@redhat.com>
Tue, 15 Aug 2023 17:05:20 +0000 (19:05 +0200)
committerHans de Goede <hdegoede@redhat.com>
Wed, 30 Aug 2023 15:27:20 +0000 (17:27 +0200)
Add a ply_guess_device_scale () helper for getting device-scale
when the physical dimensions of the output are not available.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
src/libply/ply-utils.c
src/libply/ply-utils.h

index ed6b054a6668525c53d3e0c5e3e4183d0f5947ea..fb77e74b009aa1a0e32bd9e305758ee167ec3824 100644 (file)
@@ -868,12 +868,20 @@ ply_set_device_scale (int device_scale)
 /* The minimum resolution at which we turn on a device-scale of 2 */
 #define HIDPI_LIMIT 192
 #define HIDPI_MIN_HEIGHT 1200
+#define HIDPI_MIN_WIDTH 2560 /* For heuristic / guessed device-scale */
 
-int
-ply_get_device_scale (uint32_t width,
-                      uint32_t height,
-                      uint32_t width_mm,
-                      uint32_t height_mm)
+/*
+ * If we have guessed the scale once, keep guessing to avoid
+ * changing the scale on simpledrm -> native driver switch.
+ */
+static bool guess_device_scale;
+
+static int
+get_device_scale (uint32_t width,
+                  uint32_t height,
+                  uint32_t width_mm,
+                  uint32_t height_mm,
+                  bool     guess)
 {
         int device_scale;
         double dpi_x, dpi_y;
@@ -890,6 +898,9 @@ ply_get_device_scale (uint32_t width,
         if (height < HIDPI_MIN_HEIGHT)
                 return 1;
 
+        if (guess)
+                return (width >= HIDPI_MIN_WIDTH) ? 2 : 1;
+
         /* Somebody encoded the aspect ratio (16/9 or 16/10)
          * instead of the physical size */
         if ((width_mm == 160 && height_mm == 90) ||
@@ -911,6 +922,23 @@ ply_get_device_scale (uint32_t width,
         return device_scale;
 }
 
+int
+ply_get_device_scale (uint32_t width,
+                      uint32_t height,
+                      uint32_t width_mm,
+                      uint32_t height_mm)
+{
+        return get_device_scale (width, height, width_mm, height_mm,
+                                 guess_device_scale);
+}
+
+int ply_guess_device_scale (uint32_t width,
+                            uint32_t height)
+{
+        guess_device_scale = true;
+        return get_device_scale (width, height, 0, 0, true);
+}
+
 static const char *
 ply_get_kernel_command_line (void)
 {
index 09507e0934d75fa1398ebd290de2d45d5c8e307f..3893a6f641f291ddce12f37129534f6e8a955cf1 100644 (file)
@@ -127,6 +127,9 @@ int ply_get_device_scale (uint32_t width,
                           uint32_t width_mm,
                           uint32_t height_mm);
 
+int ply_guess_device_scale (uint32_t width,
+                            uint32_t height);
+
 const char *ply_kernel_command_line_get_string_after_prefix (const char *prefix);
 bool ply_kernel_command_line_has_argument (const char *argument);
 void ply_kernel_command_line_override (const char *command_line);