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

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