From 72e7a1ed48d003977edcd244301c0a3cbd15df2c Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Mon, 25 Nov 2019 23:31:57 +0000 Subject: [PATCH] backend-drm: Parse KMS panel orientation property, apply to weston_head The KMS 'panel orientation' property allows the driver to statically declare a fixed rotation of an output device. Now that weston_head has a transform member, plumb the KMS property through to weston_head so the compositor can make a smarter choice out of the box. Signed-off-by: Lucas Stach [daniels: Extracted from one of Lucas's patches] Signed-off-by: Daniel Stone --- libweston/backend-drm/drm-internal.h | 9 +++++++++ libweston/backend-drm/kms.c | 12 ++++++++++++ libweston/backend-drm/modes.c | 26 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/libweston/backend-drm/drm-internal.h b/libweston/backend-drm/drm-internal.h index 2384a9ac..855baf15 100644 --- a/libweston/backend-drm/drm-internal.h +++ b/libweston/backend-drm/drm-internal.h @@ -200,6 +200,7 @@ enum wdrm_connector_property { WDRM_CONNECTOR_NON_DESKTOP, WDRM_CONNECTOR_CONTENT_PROTECTION, WDRM_CONNECTOR_HDCP_CONTENT_TYPE, + WDRM_CONNECTOR_PANEL_ORIENTATION, WDRM_CONNECTOR__COUNT }; @@ -224,6 +225,14 @@ enum wdrm_dpms_state { WDRM_DPMS_STATE__COUNT }; +enum wdrm_panel_orientation { + WDRM_PANEL_ORIENTATION_NORMAL = 0, + WDRM_PANEL_ORIENTATION_UPSIDE_DOWN, + WDRM_PANEL_ORIENTATION_LEFT_SIDE_UP, + WDRM_PANEL_ORIENTATION_RIGHT_SIDE_UP, + WDRM_PANEL_ORIENTATION__COUNT +}; + /** * List of properties attached to DRM CRTCs */ diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c index 192435c7..7576c006 100644 --- a/libweston/backend-drm/kms.c +++ b/libweston/backend-drm/kms.c @@ -116,6 +116,13 @@ struct drm_property_enum_info hdcp_content_type_enums[] = { }, }; +struct drm_property_enum_info panel_orientation_enums[] = { + [WDRM_PANEL_ORIENTATION_NORMAL] = { .name = "Normal", }, + [WDRM_PANEL_ORIENTATION_UPSIDE_DOWN] = { .name = "Upside Down", }, + [WDRM_PANEL_ORIENTATION_LEFT_SIDE_UP] = { .name = "Left Side Up", }, + [WDRM_PANEL_ORIENTATION_RIGHT_SIDE_UP] = { .name = "Right Side Up", }, +}; + const struct drm_property_info connector_props[] = { [WDRM_CONNECTOR_EDID] = { .name = "EDID" }, [WDRM_CONNECTOR_DPMS] = { @@ -135,6 +142,11 @@ const struct drm_property_info connector_props[] = { .enum_values = hdcp_content_type_enums, .num_enum_values = WDRM_HDCP_CONTENT_TYPE__COUNT, }, + [WDRM_CONNECTOR_PANEL_ORIENTATION] = { + .name = "panel orientation", + .enum_values = panel_orientation_enums, + .num_enum_values = WDRM_PANEL_ORIENTATION__COUNT, + }, }; const struct drm_property_info crtc_props[] = { diff --git a/libweston/backend-drm/modes.c b/libweston/backend-drm/modes.c index e12ed625..69611b08 100644 --- a/libweston/backend-drm/modes.c +++ b/libweston/backend-drm/modes.c @@ -128,6 +128,29 @@ check_non_desktop(struct drm_head *head, drmModeObjectPropertiesPtr props) return drm_property_get_value(non_desktop_info, props, 0); } +static uint32_t +get_panel_orientation(struct drm_head *head, drmModeObjectPropertiesPtr props) +{ + struct drm_property_info *orientation = + &head->props_conn[WDRM_CONNECTOR_PANEL_ORIENTATION]; + uint64_t kms_val = + drm_property_get_value(orientation, props, + WDRM_PANEL_ORIENTATION_NORMAL); + + switch (kms_val) { + case WDRM_PANEL_ORIENTATION_NORMAL: + return WL_OUTPUT_TRANSFORM_NORMAL; + case WDRM_PANEL_ORIENTATION_UPSIDE_DOWN: + return WL_OUTPUT_TRANSFORM_180; + case WDRM_PANEL_ORIENTATION_LEFT_SIDE_UP: + return WL_OUTPUT_TRANSFORM_90; + case WDRM_PANEL_ORIENTATION_RIGHT_SIDE_UP: + return WL_OUTPUT_TRANSFORM_270; + default: + assert(!"unknown property value in get_panel_orientation"); + } +} + static int parse_modeline(const char *s, drmModeModeInfo *mode) { @@ -500,6 +523,9 @@ update_head_from_connector(struct drm_head *head, weston_head_set_physical_size(&head->base, head->connector->mmWidth, head->connector->mmHeight); + weston_head_set_transform(&head->base, + get_panel_orientation(head, props)); + /* Unknown connection status is assumed disconnected. */ weston_head_set_connection_status(&head->base, head->connector->connection == DRM_MODE_CONNECTED); -- 2.34.1