summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2023-08-15 19:05:20 +0200
committerHans de Goede <hdegoede@redhat.com>2023-08-30 17:27:20 +0200
commitcfcd24976f330d9196e8ff5d81250f8b090362cd (patch)
tree4d84b7dbf830e94947c712439948c3b7338c49f4
parentb30f886b2ed716676a0121a441c6f2db0e190f15 (diff)
utils: Add ply_guess_device_scale () helper
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>
-rw-r--r--src/libply/ply-utils.c38
-rw-r--r--src/libply/ply-utils.h3
2 files changed, 36 insertions, 5 deletions
diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c
index ed6b054a..fb77e74b 100644
--- a/src/libply/ply-utils.c
+++ b/src/libply/ply-utils.c
@@ -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)
{
diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h
index 09507e09..3893a6f6 100644
--- a/src/libply/ply-utils.h
+++ b/src/libply/ply-utils.h
@@ -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);