From cfcd24976f330d9196e8ff5d81250f8b090362cd Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 15 Aug 2023 19:05:20 +0200 Subject: [PATCH 1/4] 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 --- src/libply/ply-utils.c | 38 +++++++++++++++++++++++++++++++++----- src/libply/ply-utils.h | 3 +++ 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); From 37b6cb958a8fe46b4b1b3ba99803d08b24ce8cbb Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 15 Aug 2023 18:42:46 +0200 Subject: [PATCH 2/4] drm: Initialize rotation local variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initialize rotation local variable to fix the following false positive compiler warning: src/plugins/renderers/drm/plugin.c: In function ‘get_primary_plane_rotation’: src/plugins/renderers/drm/plugin.c:485:31: warning: ‘rotation’ may be used uninitialized [-Wmaybe-uninitialized] 485 | *rotation_ret = rotation; | ~~~~~~~~~~~~~~^~~~~~~~~~ src/plugins/renderers/drm/plugin.c:419:18: note: ‘rotation’ was declared here 419 | uint64_t rotation; | ^~~~~~~~ Signed-off-by: Hans de Goede --- src/plugins/renderers/drm/plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c index b9b338f8..53f473fd 100644 --- a/src/plugins/renderers/drm/plugin.c +++ b/src/plugins/renderers/drm/plugin.c @@ -415,7 +415,7 @@ get_primary_plane_rotation (ply_renderer_backend_t *backend, drmModePlaneResPtr plane_resources; drmModePropertyPtr prop; drmModePlanePtr plane; - uint64_t rotation; + uint64_t rotation = 0; uint32_t i, j; int rotation_prop_id = -1; int primary_id = -1; From f5eb3e57c2fd3895520c0c27af012d454a9992a3 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 15 Aug 2023 18:41:29 +0200 Subject: [PATCH 3/4] drm: Add check if the driver used is simpledrm Add a check to see if the driver used is simpledrm, this is a preparation patch for adding support to set device_scale based on heuristics when using simpledrm. Signed-off-by: Hans de Goede --- src/plugins/renderers/drm/plugin.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c index 53f473fd..6845795f 100644 --- a/src/plugins/renderers/drm/plugin.c +++ b/src/plugins/renderers/drm/plugin.c @@ -141,6 +141,7 @@ struct _ply_renderer_backend ply_terminal_t *terminal; int device_fd; + bool simpledrm; char *device_name; drmModeRes *resources; @@ -971,6 +972,7 @@ on_active_vt_changed (ply_renderer_backend_t *backend) static bool load_driver (ply_renderer_backend_t *backend) { + drmVersion *version; int device_fd; ply_trace ("Opening '%s'", backend->device_name); @@ -981,6 +983,15 @@ load_driver (ply_renderer_backend_t *backend) return false; } + version = drmGetVersion (device_fd); + if (version) { + ply_trace ("drm driver: %s", version->name); + if (strcmp (version->name, "simpledrm") == 0) + backend->simpledrm = true; + + drmFreeVersion (version); + } + backend->device_fd = device_fd; drmDropMaster (device_fd); From 01702de71a93d9a0a4ddbed697fb14b9ad6ed4bf Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 15 Aug 2023 19:25:21 +0200 Subject: [PATCH 4/4] drm: Guess device-scale when using simpledrm When displaying on a simpledrm kms device the physical dimensions of the screen are unknown. Use the heuristics from ply_get_device_scale () to guess the device scale to avoid rendering things too small on 4K screens. Signed-off-by: Hans de Goede --- src/plugins/renderers/drm/plugin.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c index 6845795f..edf9eb17 100644 --- a/src/plugins/renderers/drm/plugin.c +++ b/src/plugins/renderers/drm/plugin.c @@ -1230,9 +1230,13 @@ get_output_info (ply_renderer_backend_t *backend, mode = &connector->modes[0]; } output->mode = *mode; - output->device_scale = ply_get_device_scale (mode->hdisplay, mode->vdisplay, - (!has_90_rotation) ? connector->mmWidth : connector->mmHeight, - (!has_90_rotation) ? connector->mmHeight : connector->mmWidth); + + if (backend->simpledrm) + output->device_scale = ply_guess_device_scale (mode->hdisplay, mode->vdisplay); + else + output->device_scale = ply_get_device_scale (mode->hdisplay, mode->vdisplay, + (!has_90_rotation) ? connector->mmWidth : connector->mmHeight, + (!has_90_rotation) ? connector->mmHeight : connector->mmWidth); output->connector_type = connector->connector_type; output->connected = true; out: