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