summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2015-01-18 02:17:47 -0800
committerRay Strode <rstrode@redhat.com>2016-03-03 14:32:25 -0500
commit78e8bbea1832b5e0387ad7fb6fa73129b5ac53bb (patch)
tree3e3e2e760705287dcc942cdb30f2617ccc886271
parentd70c1dc9ee0e6f63644cbe77187d162f9476cc86 (diff)
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
-rw-r--r--src/plugins/renderers/drm/plugin.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c
index b9e5ddd..49ea125 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,