drm: Check for "panel orientation" connector property

On some devices the LCD panel is mounted in the casing in such a way
that the up/top side of the panel does not match with the top side of
the device (e.g. it is mounted upside-down).

Kernel 4.16 introduces a new "panel-orientation" property on the drm
connector which allows modesetting applications / code to check for
such LCD panels.

This commit adds support for this new property and passes this to the
pixel_buffer code using the new ply_pixel_buffer_new_with_device_rotation
method, so that the pixel_buffer code will automatically rotate the
image to correct for the panel orientation.

https://bugs.freedesktop.org/show_bug.cgi?id=104714
This commit is contained in:
Hans de Goede 2017-12-12 19:47:26 +01:00 committed by Ray Strode
parent 0e4e268844
commit a6f25b7276

View file

@ -367,6 +367,53 @@ destroy_output_buffer (ply_renderer_backend_t *backend,
ply_renderer_buffer_free (backend, buffer);
}
static int
connector_orientation_prop_to_rotation (drmModePropertyPtr prop,
int orientation)
{
const char *name = prop->enums[orientation].name;
if (strcmp (name, "Upside Down") == 0)
return PLY_PIXEL_BUFFER_ROTATE_UPSIDE_DOWN;
if (strcmp (name, "Left Side Up") == 0) {
/* Left side up, rotate counter clockwise to correct */
return PLY_PIXEL_BUFFER_ROTATE_COUNTER_CLOCKWISE;
}
if (strcmp (name, "Right Side Up") == 0) {
/* Left side up, rotate clockwise to correct */
return PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE;
}
return PLY_PIXEL_BUFFER_ROTATE_UPRIGHT;
}
static int
ply_renderer_connector_get_rotation (ply_renderer_backend_t *backend,
drmModeConnector *connector)
{
drmModePropertyPtr prop;
int i, rotation;
for (i = 0; i < connector->count_props; i++) {
prop = drmModeGetProperty (backend->device_fd, connector->props[i]);
if (!prop)
continue;
if ((prop->flags & DRM_MODE_PROP_ENUM) &&
strcmp (prop->name, "panel orientation") == 0) {
rotation = connector_orientation_prop_to_rotation (prop, connector->prop_values[i]);
drmModeFreeProperty (prop);
return rotation;
}
drmModeFreeProperty (prop);
}
return PLY_PIXEL_BUFFER_ROTATE_UPRIGHT;
}
static bool
ply_renderer_head_add_connector (ply_renderer_head_t *head,
drmModeConnector *connector,
@ -402,6 +449,7 @@ ply_renderer_head_new (ply_renderer_backend_t *backend,
{
ply_renderer_head_t *head;
drmModeModeInfo *mode;
int rotation;
head = calloc (1, sizeof(ply_renderer_head_t));
@ -425,7 +473,8 @@ ply_renderer_head_new (ply_renderer_backend_t *backend,
ply_renderer_head_add_connector (head, connector, connector_mode_index);
assert (ply_array_get_size (head->connector_ids) > 0);
head->pixel_buffer = ply_pixel_buffer_new (head->area.width, head->area.height);
rotation = ply_renderer_connector_get_rotation (backend, connector);
head->pixel_buffer = ply_pixel_buffer_new_with_device_rotation (head->area.width, head->area.height, rotation);
ply_pixel_buffer_set_device_scale (head->pixel_buffer,
ply_get_device_scale (head->area.width,
head->area.height,