xf86drmMode: introduce drmModeGetConnectorTypeName

User-space often needs to print the name of a connector type.
When a new connector type is added, all user-space programs need
to be updated to support the new connector type.

Expose a function to get a connector type name in libdrm.

The names are taken from the kernel [1].

[1]: https://cgit.freedesktop.org/drm/drm/tree/drivers/gpu/drm/drm_connector.c?h=4fc8cb47fcfdc93e274a1291757e478df4f9c39b#n83

Signed-off-by: Simon Ser <contact@emersion.fr>
main
Simon Ser 2022-02-01 14:33:34 +01:00
parent f7828dc180
commit 50f8d51773
3 changed files with 63 additions and 0 deletions

View File

@ -126,6 +126,7 @@ drmModeFreePropertyBlob
drmModeFreeResources
drmModeGetConnector
drmModeGetConnectorCurrent
drmModeGetConnectorTypeName
drmModeGetCrtc
drmModeGetEncoder
drmModeGetFB

View File

@ -1747,3 +1747,56 @@ drm_public void drmModeFreeFB2(drmModeFB2Ptr ptr)
{
drmFree(ptr);
}
drm_public const char *
drmModeGetConnectorTypeName(uint32_t connector_type)
{
/* Keep the strings in sync with the kernel's drm_connector_enum_list in
* drm_connector.c. */
switch (connector_type) {
case DRM_MODE_CONNECTOR_Unknown:
return "Unknown";
case DRM_MODE_CONNECTOR_VGA:
return "VGA";
case DRM_MODE_CONNECTOR_DVII:
return "DVI-I";
case DRM_MODE_CONNECTOR_DVID:
return "DVI-D";
case DRM_MODE_CONNECTOR_DVIA:
return "DVI-A";
case DRM_MODE_CONNECTOR_Composite:
return "Composite";
case DRM_MODE_CONNECTOR_SVIDEO:
return "SVIDEO";
case DRM_MODE_CONNECTOR_LVDS:
return "LVDS";
case DRM_MODE_CONNECTOR_Component:
return "Component";
case DRM_MODE_CONNECTOR_9PinDIN:
return "DIN";
case DRM_MODE_CONNECTOR_DisplayPort:
return "DP";
case DRM_MODE_CONNECTOR_HDMIA:
return "HDMI-A";
case DRM_MODE_CONNECTOR_HDMIB:
return "HDMI-B";
case DRM_MODE_CONNECTOR_TV:
return "TV";
case DRM_MODE_CONNECTOR_eDP:
return "eDP";
case DRM_MODE_CONNECTOR_VIRTUAL:
return "Virtual";
case DRM_MODE_CONNECTOR_DSI:
return "DSI";
case DRM_MODE_CONNECTOR_DPI:
return "DPI";
case DRM_MODE_CONNECTOR_WRITEBACK:
return "Writeback";
case DRM_MODE_CONNECTOR_SPI:
return "SPI";
case DRM_MODE_CONNECTOR_USB:
return "USB";
default:
return NULL;
}
}

View File

@ -475,6 +475,15 @@ extern drmModeObjectListPtr drmModeGetLease(int fd);
extern int drmModeRevokeLease(int fd, uint32_t lessee_id);
/**
* Get a string describing a connector type.
*
* NULL is returned if the connector type is unsupported. Callers should handle
* this gracefully, e.g. by falling back to "Unknown" or printing the raw value.
*/
extern const char *
drmModeGetConnectorTypeName(uint32_t connector_type);
#if defined(__cplusplus)
}
#endif