Blame SOURCES/0004-drm-Check-for-panel-orientation-connector-property.patch

a802d9
From a6f25b727698a2382e332ab566ed39ee30f8efdc Mon Sep 17 00:00:00 2001
a802d9
From: Hans de Goede <hdegoede@redhat.com>
a802d9
Date: Tue, 12 Dec 2017 19:47:26 +0100
a802d9
Subject: [PATCH 4/6] drm: Check for "panel orientation" connector property
a802d9
a802d9
On some devices the LCD panel is mounted in the casing in such a way
a802d9
that the up/top side of the panel does not match with the top side of
a802d9
the device (e.g. it is mounted upside-down).
a802d9
a802d9
Kernel 4.16 introduces a new "panel-orientation" property on the drm
a802d9
connector which allows modesetting applications / code to check for
a802d9
such LCD panels.
a802d9
a802d9
This commit adds support for this new property and passes this to the
a802d9
pixel_buffer code using the new ply_pixel_buffer_new_with_device_rotation
a802d9
method, so that the pixel_buffer code will automatically rotate the
a802d9
image to correct for the panel orientation.
a802d9
a802d9
https://bugs.freedesktop.org/show_bug.cgi?id=104714
a802d9
---
a802d9
 src/plugins/renderers/drm/plugin.c | 51 +++++++++++++++++++++++++++++-
a802d9
 1 file changed, 50 insertions(+), 1 deletion(-)
a802d9
a802d9
diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c
a802d9
index b93e8e4..f495854 100644
a802d9
--- a/src/plugins/renderers/drm/plugin.c
a802d9
+++ b/src/plugins/renderers/drm/plugin.c
a802d9
@@ -367,6 +367,53 @@ destroy_output_buffer (ply_renderer_backend_t *backend,
a802d9
         ply_renderer_buffer_free (backend, buffer);
a802d9
 }
a802d9
 
a802d9
+static int
a802d9
+connector_orientation_prop_to_rotation (drmModePropertyPtr prop,
a802d9
+                                        int orientation)
a802d9
+{
a802d9
+        const char *name = prop->enums[orientation].name;
a802d9
+
a802d9
+        if (strcmp (name, "Upside Down") == 0)
a802d9
+                return PLY_PIXEL_BUFFER_ROTATE_UPSIDE_DOWN;
a802d9
+
a802d9
+        if (strcmp (name, "Left Side Up") == 0) {
a802d9
+                /* Left side up, rotate counter clockwise to correct */
a802d9
+                return PLY_PIXEL_BUFFER_ROTATE_COUNTER_CLOCKWISE;
a802d9
+        }
a802d9
+
a802d9
+        if (strcmp (name, "Right Side Up") == 0) {
a802d9
+                /* Left side up, rotate clockwise to correct */
a802d9
+                return PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE;
a802d9
+        }
a802d9
+
a802d9
+        return PLY_PIXEL_BUFFER_ROTATE_UPRIGHT;
a802d9
+}
a802d9
+
a802d9
+static int
a802d9
+ply_renderer_connector_get_rotation (ply_renderer_backend_t *backend,
a802d9
+                                     drmModeConnector       *connector)
a802d9
+{
a802d9
+        drmModePropertyPtr prop;
a802d9
+        int i, rotation;
a802d9
+
a802d9
+        for (i = 0; i < connector->count_props; i++) {
a802d9
+                prop = drmModeGetProperty (backend->device_fd, connector->props[i]);
a802d9
+                if (!prop)
a802d9
+                        continue;
a802d9
+
a802d9
+                if ((prop->flags & DRM_MODE_PROP_ENUM) &&
a802d9
+                    strcmp (prop->name, "panel orientation") == 0) {
a802d9
+                         rotation = connector_orientation_prop_to_rotation (prop, connector->prop_values[i]);
a802d9
+                         drmModeFreeProperty (prop);
a802d9
+                         return rotation;
a802d9
+                }
a802d9
+
a802d9
+                drmModeFreeProperty (prop);
a802d9
+        }
a802d9
+
a802d9
+        return PLY_PIXEL_BUFFER_ROTATE_UPRIGHT;
a802d9
+}
a802d9
+
a802d9
 static bool
a802d9
 ply_renderer_head_add_connector (ply_renderer_head_t *head,
a802d9
                                  drmModeConnector    *connector,
a802d9
@@ -402,6 +449,7 @@ ply_renderer_head_new (ply_renderer_backend_t *backend,
a802d9
 {
a802d9
         ply_renderer_head_t *head;
a802d9
         drmModeModeInfo *mode;
a802d9
+        int rotation;
a802d9
 
a802d9
         head = calloc (1, sizeof(ply_renderer_head_t));
a802d9
 
a802d9
@@ -425,7 +473,8 @@ ply_renderer_head_new (ply_renderer_backend_t *backend,
a802d9
         ply_renderer_head_add_connector (head, connector, connector_mode_index);
a802d9
         assert (ply_array_get_size (head->connector_ids) > 0);
a802d9
 
a802d9
-        head->pixel_buffer = ply_pixel_buffer_new (head->area.width, head->area.height);
a802d9
+        rotation = ply_renderer_connector_get_rotation (backend, connector);
a802d9
+        head->pixel_buffer = ply_pixel_buffer_new_with_device_rotation (head->area.width, head->area.height, rotation);
a802d9
         ply_pixel_buffer_set_device_scale (head->pixel_buffer,
a802d9
                                            ply_get_device_scale (head->area.width,
a802d9
                                                                  head->area.height,
a802d9
-- 
a802d9
2.17.0
a802d9