From: Giovanni Campagna Date: Sun, 18 Jan 2015 10:17:47 +0000 (-0800) Subject: drm: set a device scale of 2 on HiDPI X-Git-Tag: 0.9.3~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78e8bbea1832b5e0387ad7fb6fa73129b5ac53bb;p=thirdparty%2Fplymouth.git drm: set a device scale of 2 on HiDPI Using the same heuristics as gnome-settings-daemon (which ensures that the bootsplash will be scaled if and only if the running system is) https://bugs.freedesktop.org/show_bug.cgi?id=84482 --- diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c index b9e5ddd6..49ea1256 100644 --- a/src/plugins/renderers/drm/plugin.c +++ b/src/plugins/renderers/drm/plugin.c @@ -61,6 +61,12 @@ #define BYTES_PER_PIXEL (4) +/* The minimum resolution at which we turn on a device-scale of 2 */ +#define HIDPI_LIMIT 192 +#define HIDPI_MIN_HEIGHT 1200 +/* From http://en.wikipedia.org/wiki/4K_resolution#Resolutions_of_common_formats */ +#define SMALLEST_4K_WIDTH 3656 + struct _ply_renderer_head { ply_renderer_backend_t *backend; @@ -391,6 +397,40 @@ ply_renderer_head_add_connector (ply_renderer_head_t *head, return true; } +static int get_device_scale (uint32_t width, + uint32_t height, + uint32_t width_mm, + uint32_t height_mm) +{ + int device_scale; + double dpi_x, dpi_y; + + device_scale = 1; + + if (height < HIDPI_MIN_HEIGHT) + return 1; + + /* Somebody encoded the aspect ratio (16/9 or 16/10) + * instead of the physical size */ + if ((width_mm == 160 && height_mm == 90) || + (width_mm == 160 && height_mm == 100) || + (width_mm == 16 && height_mm == 9) || + (width_mm == 16 && height_mm == 10)) + return 1; + + if (width_mm > 0 && height_mm > 0) { + dpi_x = (double)width / (width_mm / 25.4); + dpi_y = (double)height / (height_mm / 25.4); + /* We don't completely trust these values so both + must be high, and never pick higher ratio than + 2 automatically */ + if (dpi_x > HIDPI_LIMIT && dpi_y > HIDPI_LIMIT) + device_scale = 2; + } + + return device_scale; +} + static ply_renderer_head_t * ply_renderer_head_new (ply_renderer_backend_t *backend, drmModeConnector *connector, @@ -425,6 +465,11 @@ ply_renderer_head_new (ply_renderer_backend_t *backend, assert (ply_array_get_size (head->connector_ids) > 0); head->pixel_buffer = ply_pixel_buffer_new (head->area.width, head->area.height); + ply_pixel_buffer_set_device_scale (head->pixel_buffer, + get_device_scale (head->area.width, + head->area.height, + connector->mmWidth, + connector->mmHeight)); ply_trace ("Creating %ldx%ld renderer head", head->area.width, head->area.height); ply_pixel_buffer_fill_with_color (head->pixel_buffer, NULL,