]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
libply: unify get_device_scale() method in library
authorCosimo Cecchi <cosimoc@gnome.org>
Wed, 9 Sep 2015 22:32:27 +0000 (15:32 -0700)
committerRay Strode <rstrode@redhat.com>
Thu, 3 Mar 2016 19:32:25 +0000 (14:32 -0500)
Unify the two copies of this method inside libply. Also add back a check
for 4K displays that went missing.

https://bugs.freedesktop.org/show_bug.cgi?id=84482

src/libply/ply-utils.c
src/libply/ply-utils.h
src/plugins/renderers/drm/plugin.c
src/plugins/renderers/x11/plugin.c

index 5c8510c53256d5fe8e8ba0b8a8c85528b1ca3fdc..feee6e6695d65de553a5659ee250c8800e24812d 100644 (file)
@@ -936,4 +936,53 @@ out:
 
         return (pid_t) ppid;
 }
+
+/* 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
+
+int
+ply_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;
+        const char *force_device_scale;
+
+        device_scale = 1;
+
+        if ((force_device_scale = getenv ("PLYMOUTH_FORCE_SCALE")))
+                return strtoul (force_device_scale, NULL, 0);
+
+        if (width >= SMALLEST_4K_WIDTH)
+                return 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;
+}
+
 /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
index b9a28d0dfad02464d66e162593a49e8411aa4ada..10bdb5d0f497ebcdc3504f83994e220642cd5125 100644 (file)
@@ -120,6 +120,11 @@ int ply_utf8_string_get_length (const char *string,
 char *ply_get_process_command_line (pid_t pid);
 pid_t ply_get_process_parent_pid (pid_t pid);
 
+int ply_get_device_scale (uint32_t width,
+                          uint32_t height,
+                          uint32_t width_mm,
+                          uint32_t height_mm);
+
 #endif
 
 #endif /* PLY_UTILS_H */
index 49ea12563d75666f7d783c02a5e5f52556c92978..bfe9f13e715e84f30587ebcaaa906e66b1f85942 100644 (file)
@@ -54,6 +54,7 @@
 #include "ply-hashtable.h"
 #include "ply-rectangle.h"
 #include "ply-region.h"
+#include "ply-utils.h"
 #include "ply-terminal.h"
 
 #include "ply-renderer.h"
 
 #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;
@@ -397,40 +392,6 @@ 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,
@@ -466,10 +427,10 @@ ply_renderer_head_new (ply_renderer_backend_t *backend,
 
         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_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,
index ce1659c3d1faa4bd68933d8bec60622da5f998eb..a44c8068d708779cc3ff8fc6afc0028a8fc79be7 100644 (file)
@@ -56,6 +56,7 @@
 #include "ply-logger.h"
 #include "ply-rectangle.h"
 #include "ply-region.h"
+#include "ply-utils.h"
 
 #include "ply-renderer.h"
 #include "ply-renderer-plugin.h"
@@ -209,50 +210,6 @@ create_fake_multi_head_setup (ply_renderer_backend_t *backend)
         ply_list_append_data (backend->heads, head);
 }
 
-/* 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
-
-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;
-        const char *force_device_scale;
-
-        device_scale = 1;
-
-        if ((force_device_scale = getenv ("PLYMOUTH_FORCE_SCALE")))
-                return strtoul (force_device_scale, NULL, 0);
-
-        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 void
 create_fullscreen_single_head_setup (ply_renderer_backend_t *backend)
 {
@@ -272,9 +229,9 @@ create_fullscreen_single_head_setup (ply_renderer_backend_t *backend)
         head->area.width = monitor_geometry.width;
         head->area.height = monitor_geometry.height;
         head->is_fullscreen = true;
-        head->scale = get_device_scale (monitor_geometry.width,
-                                        monitor_geometry.height,
-                                        width_mm, height_mm);
+        head->scale = ply_get_device_scale (monitor_geometry.width,
+                                            monitor_geometry.height,
+                                            width_mm, height_mm);
         head->pixel_buffer = ply_pixel_buffer_new (head->area.width, head->area.height);
         ply_pixel_buffer_set_device_scale (head->pixel_buffer, head->scale);